junit基础学习之-测试service层(3)
测试步骤:
在之前的文章中已经加了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 正确!");
} }
}
junit基础学习之-测试service层(3)的更多相关文章
- junit基础学习之-测试controller层(2)
准备工作: eclipse本身带有junit4,可以直接build path,加入junit. 连接数据库的配置文件需要修改,之前的文件是采用properties+xml文件的形式,但是在测试的时候因 ...
- junit基础学习之-多线程测试(6)
步骤: 1.定义单个TestRunner 2.重载单个TestRunner的runTest() 3.定义TestRunner数组,并添加多个TestRunner 4.MultiThreadedTest ...
- junit基础学习之-引用spring容器的测试(7)
context 自动注入的文章链接:http://www.360doc.com/content/11/0815/09/2371584_140471325.shtml
- springboot测试service层的单元测试
package com.test.service; import com.task.Application;import com.task.model.po.TaskRecordDo;import o ...
- junit基础学习之-参数初始化(5)
package swust.edu.cn.postdoctors.service.impl; import java.util.Arrays; import java.util.Collection; ...
- junit基础学习之-简介(1)
JUnit介绍 JUnit是一个开源的Java单元测试框架,由 Erich Gamma 和 Kent Beck 开发完成. 1 JUnit简介 JUnit主要用来帮助开发人员进行Java的单元测试, ...
- junit基础学习
学习地址一:http://blog.csdn.net/andycpp/article/details/1327147/ 学习地址二:http://blog.csdn.net/zen99t/articl ...
- Android项目之HomeHealth基础学习2:Service
一. Service简单介绍 Service是android 系统中的四大组件之中的一个(Activity.Service.BroadcastReceiver.ContentProvider),它跟A ...
- junit基础学习之-junit3和4的区别(4)
junit3和junit4的使用区别如下 1.在JUnit3中需要继承TestCase类,但在JUnit4中已经不需要继承TestCase 2.在JUnit3中需要覆盖TestCase中的setUp和 ...
随机推荐
- 5、mysql的连接查询
1.内联查询 >inner join 或 join 2.外联查询 (1)左连接 >left outer join 或 left join (2)右连接 >right outer jo ...
- Day10 - A - Rescue the Princess ZOJ - 4097
Princess Cjb is caught by Heltion again! Her knights Little Sub and Little Potato are going to Helti ...
- 关于syx的npy
请认准官方女友----- STL 任何人在不得syx同意下不能传播其它谣言
- Linux打印变量、环境配置、别名和文件删除操作
一.打印命令 1.echo打印命令 a.打印环境变量 echo $Path b.打印Path命令目录 which,比如:which ls表示打印的是Path目录中第一定义的全局变量的目录中命令. 二. ...
- 线程与FORK
1.线程锁的问题 需要调用进程线程锁处理函数 prefork-----获取父亲进程锁----在fork掉用之前,目的是为了在子进程中获取到可释放的锁 parentfork----释放父亲进程锁 chi ...
- HTML设置目标页面在新窗口打开
在使用<a></a>标签进行超链接跳转时,目标页面默认在当前页面中打开. 如果希望当前页面中所有超链接跳转页面的时候,都在新窗口中打开,那么只需要在head标签中设置 base ...
- JuJu团队1月3号工作汇报
JuJu团队1月3号工作汇报 JuJu Scrum 团队成员 今日工作 剩余任务 困难 飞飞 测试dataloader 将model嵌入GUI 无 婷婷 调试代码 提升acc 无 恩升 -- 写p ...
- when_did_you_born-瞟来的wp
继上文,这次开始嫖when_did_you_born这题.前面的步骤大致是一样的就不赘述了,直接到代码分析. 字符串 这次呢在main函数处 按下F5进入调试 查看反汇编代码 可以清楚的看到它的逻辑一 ...
- 结题报告:luogu P2014
题目链接:P2014 选课 简单的树形\(dp\),借助\(dfs\)实现. 一般的树形\(dp\)数组是需要二维的,其中一维记录节点(编号或父/子节点的状态(有时三维)),另一维记录权值或计数. 重 ...
- 10. Regular Expression Matching正则表达式匹配
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...