Spring对junit的整合

 package cn.mepu.service;

 import cn.mepu.config.SpringConfiguration;
 import cn.mepu.domain.Account;
 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 java.util.List;

 /**
  * @author shkstart
  * @create 2019-11-08 10:45
  * junit的整合:
  *  junit不会关注我们是否使用Spring框架,所以加了@Autowired注解也不能注入
  *  说明测试方法执行时没有ioc容器
  *      方法:换了junit的main方法在pom中导入spring-test
  *      使用junit提供的@Runwith注解把main方法替换为spring提供的传入字节码
  *      告知spring的运行器spring和ioc是基于注解还是xml,说明位置
  *          @ContextConfiguration
  *              locations=xml的位置加classpath关键字表示类路径下
  *              classes=指定注解位置
  *      当使用spring5.x版本时,junit的jar包必须是4.1.2及以上
  */
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(classes = SpringConfiguration.class)
 public class AccountServiceTest {

     @Autowired
     private AccountService service;

     @Test
     public void testFindAll(){
     //3.执行方法
         List<Account> accounts = service.findAllAccount();
         for (Account account : accounts) {
             System.out.println("account = " + account);
         }

     }

     @Test
     public void testFindOne(){
         //3.执行方法
         Account account = service.findAccountById(1);
         System.out.println(account);
     }

     @Test
     public void testSave(){
         //3.执行方法
         service.saveAccount(new Account(1,"DDD",1234));
     }

     @Test
     public void testUpdate(){
         //3.执行方法
         service.updateAccount(new Account(1,"DDD",2345));
     }

     @Test
     public void testDelete(){

         //3.执行方法
         service.deleteAccount(4);
     }
 }

Spring对junit的整合的更多相关文章

  1. Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程

    一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module  project 二.Maven聚合 在某个项目的p ...

  2. Spring与Junit测试整合

    一.引入spring测试包:text包 二.@RunWith:指定spring对junit提供的一个运行器 @ContextConfiguration:  locations指定spring配置文件位 ...

  3. Spring集成JUnit测试

    1.程序中有Junit环境2.导入一个jar包.spring与junit整合jar包 spring-test-3.2.0.RELEASE.jar3.测试代码 @RunWith(SpringJUnit4 ...

  4. 基于maven进行spring 和mybatis的整合(Myeclpise)

    学习日记:基于maven进行spring和mybatis的整合,进行分页查询 什么是maven:maven是一个项目管理工具,使用maven可以自动管理java项目的整个生命周期,包括编译.构建.测试 ...

  5. spring和redis的整合

    spring和redis的整合-超越昨天的自己系列(7) 超越昨天的自己系列(7) 扯淡:  最近一直在慢慢多学习各个组件,自己搭建出一些想法.是一个涉猎的过程,慢慢意识到知识是可以融汇贯通,举一反三 ...

  6. Spring+SpringMVC+MyBatis+easyUI整合基础篇(六)maven整合SSM

    写在前面的话   承接前文<Spring+SpringMVC+MyBatis+easyUI整合基础篇(五)讲一下maven>,本篇所讲述的是如何使用maven与原ssm项目整合,使得一个普 ...

  7. spring和hibernate的整合

    阅读目录 一.概述 二.整合步骤 1.大致步骤 2.具体分析 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让H ...

  8. mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)

    文章介绍结构一览 一.使用maven创建web项目 1.新建maven项目 2.修改jre版本 3.修改Project Facts,生成WebContent文件夾 4.将WebContent下的两个文 ...

  9. Spring+Spring MVC+Mybatis 框架整合开发(半注解半配置文件)

    项目结构: (代码里面都有注释) 一.在pom文件中依赖jar包 因为我这里分了模块,所以有父子级的共两个pom文件 父级: <?xml version="1.0" enco ...

随机推荐

  1. OI中的快速傅里叶变换(FFT)

    快速傅里叶变换(FFT)                                                                               ---- LLpp ...

  2. Redis 布隆过滤器

    1.布隆过滤器 内容参考:https://www.jianshu.com/p/2104d11ee0a2 1.数据结构 布隆过滤器是一个BIT数组,本质上是一个数据,所以可以根据下标快速找数据 2.哈希 ...

  3. JS鼠标提示框效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Arch安装墨刀(产品原型工具)

    Arch通过aur安装墨刀的时候报错,查看PKGBUILD发现下载地址错误("https://s3.cn-north-1.amazonaws.com.cn/modao/download&qu ...

  5. Centos7搭建SkyWalking分布式追踪,以mysql为存储

    Skywalking专门为微服务架构和云原生架构系统而设计并且支持分布式链路追踪的APM系统,即应用性能监控系统,为微服务架构和云原生架构系统设计.它通过探针自动收集所需的指标,并进行分布式追踪.通过 ...

  6. python 对redis key的基本操作

    首先看一下Python 操作redis.StrictRedis 的初始化方法__init__ def __init__(self, host='localhost', port=6379, db=0, ...

  7. python操作pymysql

    #_author:来童星#date:2019/12/19import pymysql#1.打开数据库连接db=pymysql.connect('localhost','root','root','te ...

  8. 聊一聊JavaScript中的事件循环

    一.概念:事件循环 JavaScript是单线程的 1.整片 script 整体代码(第一个宏任务)放到执行栈中,执行之后,会触发很多方法 这些方法只能一个个的顺序执行,不能并发 2.这些要执行的方法 ...

  9. 4-基于DoG的特征检测子(SIFT:稳定性好,实时性差)

    opencv实现 详细原理:https://blog.csdn.net/u010440456/article/details/81483145

  10. sublime text3 nodejs控制台输出结果中文乱码

    在sublime text3安装完nodejs的插件后,运行console.log("你好"),发现控制台出现中文乱码,解决办法:Preferences-> Browser ...