测试步骤:

在之前的文章中已经加了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. Python学习第一课——if-else

    #if 基本语句 if 1==1: print("如果条件为真,if执行该语句") else: print("如果条件为假,if则执行这条语句") #if 多重 ...

  2. lnmp1.5安装swoole

    php7.2安装swoole-4.0.1.tgz     php5.6安装swoole-1.10.4.tgz wget http://pecl.php.net/get/swoole-4.0.1.tgz ...

  3. IOS TableView 用法

    1.在视图上创建TableView( 拖控件),为ViewController创建UITableView属性(链接至TableView)和NSArray属性(存储数据) ViewController. ...

  4. 让Nutz支持最快的模板引擎Smarty4j

    Smarty4j是一个开源的模板引擎.没错,它就是著名的php模板引擎之Java移植版. 它特点就是将模板文件或者字符串编译成java类直接执行,所以效率比一般的模板解释的方式处理要快.它发展较晚,所 ...

  5. Python format语法

    a = {"name" : "alex","age":16} v = "my name is {name}, my age is ...

  6. 【capstone/ropgadget】环境配置

    具体环境配置可参考 https://github.com/JonathanSalwan/ROPgadget/tree/master 作者给出的安装方式 但具体配置中出现了问题,如引用时出现如下错误: ...

  7. TFIDF介绍

    简介 全称: Term Frequency-inverse document frequency(文本频率与逆文档频率指数) 目的: 表征一个token(可以是一个字或者一个词)的重要程度 是Elas ...

  8. python Scipy积分运算大全(integrate模块——一重、二重及三重积分)

    python中Scipy模块求取积分的方法: SciPy下实现求函数的积分的函数的基本使用,积分,高等数学里有大量的讲述,基本意思就是求曲线下面积之和. 其中rn可认为是偏差,一般可以忽略不计,wi可 ...

  9. IDA使用初步

    按空格看结构图,再按空格看汇编代码,按F5反编译 shift+F12 搜索中文字符串,通过字符串所在位置定位关键信息. 双击可能出flag的语句跳转至关键字符串. 想F5生成C伪代码,先crtl+X打 ...

  10. 08 MySQL存储引擎

    查询当前默认存储引擎     SHOW VARIABLES LIKE 'table_type' ;      查询当前数据库支持的引擎有哪些 :     SHOW ENGINES \G   -- 推荐 ...