junit基础学习之-测试service层(3)
2015-08-15 21:23
351 查看
测试步骤:
在之前的文章中已经加了junit的环境,这就不需要了。
1.加载junit类,spring配置文件,指明junit测试器,@Runwith
2.定义变量,service,不可以使用spring注解,因为spring注解是建立在server上的。
3.初始化@Before注解。
4.实现测试方法,@Test注解。
在之前的文章中已经加了junit的环境,这就不需要了。
1.加载junit类,spring配置文件,指明junit测试器,@Runwith
2.定义变量,service,不可以使用spring注解,因为spring注解是建立在server上的。
3.初始化@Before注解。
4.实现测试方法,@Test注解。
package swust.edu.cn.postdoctors.service.impl; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import swust.edu.cn.postdoctors.service.UserService; import junit.framework.TestCase; @RunWith(SpringJUnit4ClassRunner.class) // 整合 @ContextConfiguration(locations={"classpath:spring-mybatis-test.xml"}) // 加载配置 public class UserServiceTest extends TestCase { private UserService userService; public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; } //省略setget @Test public void testSelectUserByLoginNameAndPswd() throws Exception { swust.edu.cn.postdoctors.model.User resUser = null ; resUser = userService.findUserByLoginNameAndPswd("smx", "123"); if(resUser == null){ System.out.println("userService 出错!"); }else{ System.out.println("userService 正确!"); } } }
相关文章推荐
- MongoDB Helper的简单封装
- hdu 1130 How Many Trees?(卡特兰数,大数的乘法与除法)
- UVa10986_Sending email(最短)(白皮书图论的话题)
- Python3 字符串
- 2440 ads启动代码的中断处理流程分析
- OMS中的AGENT变化如何处理
- vim文本编辑器
- 笔试面试错题集2
- poj 2528 (线段树+离散化)
- 排序算法总结
- 连续子序列的长度的最小值(尺取法)
- MongoDB的一些基本操作
- 上传项目代码到github
- poj 2528 (线段树+离散化)
- 多个数的最小公倍数的求法
- Linux简介
- QlikView线图高亮选择尺寸
- Codeforces Gym 100203G Good elements 暴力乱搞
- 关于C# wpf Frame 一次加载多个Page 的问题
- GP规范学习(三)