测试步骤:

在之前的文章中已经加了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)的更多相关文章

  1. junit基础学习之-测试controller层(2)

    准备工作: eclipse本身带有junit4,可以直接build path,加入junit. 连接数据库的配置文件需要修改,之前的文件是采用properties+xml文件的形式,但是在测试的时候因 ...

  2. junit基础学习之-多线程测试(6)

    步骤: 1.定义单个TestRunner 2.重载单个TestRunner的runTest() 3.定义TestRunner数组,并添加多个TestRunner 4.MultiThreadedTest ...

  3. junit基础学习之-引用spring容器的测试(7)

    context 自动注入的文章链接:http://www.360doc.com/content/11/0815/09/2371584_140471325.shtml

  4. springboot测试service层的单元测试

    package com.test.service; import com.task.Application;import com.task.model.po.TaskRecordDo;import o ...

  5. junit基础学习之-参数初始化(5)

    package swust.edu.cn.postdoctors.service.impl; import java.util.Arrays; import java.util.Collection; ...

  6. junit基础学习之-简介(1)

    JUnit介绍 JUnit是一个开源的Java单元测试框架,由 Erich Gamma 和 Kent Beck 开发完成. 1  JUnit简介 JUnit主要用来帮助开发人员进行Java的单元测试, ...

  7. junit基础学习

    学习地址一:http://blog.csdn.net/andycpp/article/details/1327147/ 学习地址二:http://blog.csdn.net/zen99t/articl ...

  8. Android项目之HomeHealth基础学习2:Service

    一. Service简单介绍 Service是android 系统中的四大组件之中的一个(Activity.Service.BroadcastReceiver.ContentProvider),它跟A ...

  9. junit基础学习之-junit3和4的区别(4)

    junit3和junit4的使用区别如下 1.在JUnit3中需要继承TestCase类,但在JUnit4中已经不需要继承TestCase 2.在JUnit3中需要覆盖TestCase中的setUp和 ...

随机推荐

  1. C# 中的委托和事件 转载张子阳的

        C# 中的委托和事件 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人 ...

  2. Android简单计时器(转)

    原文:http://blog.csdn.net/fwwdn/article/details/7550822 本文利用ContextMenu(上下文菜单),Chronometer实现简单计数器. Mai ...

  3. 四、spring集成ibatis进行项目中dao层基类封装

    Apache iBatis(现已迁至Google Code下发展,更名为MyBatis)是当前IT项目中使用很广泛的一个半自动ORM框架,区别于Hibernate之类的全自动框架,iBatis对数据库 ...

  4. taucs库的使用方法(VS2012)

    第一步:到taucs主页下载taucs,我下载的是:Version 2.2 of the code, with external libraries 第二步:在visual studio tools下 ...

  5. C语言学习从入门到精通书籍,10万读者都认可

    C语言程序设计从入门到精通 10万读者认可的编程图书精粹 零基础自学编程的入门图书 详解C语言编程思想和核心技术 很多初学者,对C语言.c++的概念都是模糊不清的,C语言.c++是什么,能做什么,学的 ...

  6. python 函数map()、filter()、reduce()

    map()函数    将一个列表进行遍历,对每一个字符串进行处理: 例如: num_list = ["我","是","哈哈","太 ...

  7. Vivado ILA观察信号和调试过程

    先简单介绍一下ILA(Integrated Logic Analyzer)生成方法.这里有两种办法完成Debug Core的配置和实现. 方法一.mark_debug综合选项+Set Up Debug ...

  8. [题解 LuoguP4491 [HAOI2018]染色

    传送门 神仙计数题 Orz 先令\(F[k]\)表示出现次数恰好为\(S\)次的颜色恰好有\(k\)中的方案数,那么 \[Ans=\sum\limits_{i=0}^mW_iF[i]\] 怎么求\(F ...

  9. 三 Road

    3—5年程序员的发展和出路在哪里? 是继续做技术人,还是向管理者发力?是继续留在大公司,还是转投潜力小公司?如果没有核心竞争力,入行一两年的新程序员朋友是可以替代你大部分工作的,而且薪资还低,要怎么办 ...

  10. Day6 - I - Sticks Problem POJ - 2452

    Xuanxuan has n sticks of different length. One day, she puts all her sticks in a line, represented b ...