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和 ...
随机推荐
- 【剑指Offer面试编程题】题目1283:第一个只出现一次的字符--九度OJ
题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现一次的字符. 输入: 输入有多组数据 每一组输入一个字符串. 输出: 输出第一个只出现一次的 ...
- Mybatis+Spring的整合练习
一.建立数据库.建表 二.新建maven项目 三.添加依赖 <dependencies> <dependency> <groupId>junit</group ...
- 【攻防世界】 高手进阶区 Recho WP
0x00 考察点 考察点有三个: ROP链构造 Got表劫持 pwntools的shutdown功能 0x01 程序分析 上来三板斧 file一下 checksec --file XXX chmod ...
- Android 如何从系统图库中选择图片
转:http://blog.csdn.net/tody_guo/article/details/7560270 这几天我都在做Android的App,同时学习它的API,我将分享一些我学到的东西,比如 ...
- 百度统计数据导出demo的坑
1.用户名中文的问题 由于demo文件格式的问题,如果用户名使用中文的话,会出现一下问题 ----------------------preLogin---------------------- [ ...
- IEEE Spectrum 2014年十大编程语言盘点
近日,IEEE Spectrum推出 了一个最流行的编程语言排行榜.排行榜筛选了 12 项指标,综合了 10 个来源(含 IEEE Xplore.Google.GitHub)的数据,最终评选出了下面这 ...
- bootstrap上下左右条纹边框悬停表格的使用
懒得找地址:https://jingyan.baidu.com/album/0bc808fc3d88941bd585b94c.html?picindex=1
- git/github error: failed to push some refs to 'https://github.com/shenhaha/cloudletter.git'
git 提交代码到github上报如下错误 报错分析: 解决方法: 关闭这两个设置 再次提交代码 success
- ROS-3 : Catkin工作空间和ROS功能包
一.创建一个Catkin工作空间 步骤一:构建catkin工作空间 安装完成ROS版本后,设置好环境变量:$ source /opt/ros/kinetic/setup.bash.然后即可创建一个ca ...
- Luogu神贴合辑
1.扩散性百万甜面包 - 陈乙己 2.Unknown_Error - 说句闲话:研究珂学的最好方法是