Spring对junit的整合
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的整合的更多相关文章
- Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程
一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module project 二.Maven聚合 在某个项目的p ...
- Spring与Junit测试整合
一.引入spring测试包:text包 二.@RunWith:指定spring对junit提供的一个运行器 @ContextConfiguration: locations指定spring配置文件位 ...
- Spring集成JUnit测试
1.程序中有Junit环境2.导入一个jar包.spring与junit整合jar包 spring-test-3.2.0.RELEASE.jar3.测试代码 @RunWith(SpringJUnit4 ...
- 基于maven进行spring 和mybatis的整合(Myeclpise)
学习日记:基于maven进行spring和mybatis的整合,进行分页查询 什么是maven:maven是一个项目管理工具,使用maven可以自动管理java项目的整个生命周期,包括编译.构建.测试 ...
- spring和redis的整合
spring和redis的整合-超越昨天的自己系列(7) 超越昨天的自己系列(7) 扯淡: 最近一直在慢慢多学习各个组件,自己搭建出一些想法.是一个涉猎的过程,慢慢意识到知识是可以融汇贯通,举一反三 ...
- Spring+SpringMVC+MyBatis+easyUI整合基础篇(六)maven整合SSM
写在前面的话 承接前文<Spring+SpringMVC+MyBatis+easyUI整合基础篇(五)讲一下maven>,本篇所讲述的是如何使用maven与原ssm项目整合,使得一个普 ...
- spring和hibernate的整合
阅读目录 一.概述 二.整合步骤 1.大致步骤 2.具体分析 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让H ...
- mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)
文章介绍结构一览 一.使用maven创建web项目 1.新建maven项目 2.修改jre版本 3.修改Project Facts,生成WebContent文件夾 4.将WebContent下的两个文 ...
- Spring+Spring MVC+Mybatis 框架整合开发(半注解半配置文件)
项目结构: (代码里面都有注释) 一.在pom文件中依赖jar包 因为我这里分了模块,所以有父子级的共两个pom文件 父级: <?xml version="1.0" enco ...
随机推荐
- Spring Enable高级应用及原理
Enable* 之前的文章用到了一些Enable*开头的注解,比如EnableAsync.EnableScheduling.EnableAspectJAutoProxy.EnableCaching等, ...
- 热修复设计之CLASS_ISPREVERIFIED(二)
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从CLASS_ISPREVERIFIED实战来介绍热 ...
- 关于软件IntelliJ IDEA的使用技巧(四)
二,IntelliJ IDEA的工具栏介绍 2,IntelliJ IDEA菜单栏 (9)Run运行 ✌1.Run'All Features in :src':运行scr中所有的特征 ✌2.Debug ...
- document.createDocumentFragment()的用法
createDocumentFragment有什么作用呢? 调用多次document.body.append(),每次都要刷新页面一次.效率也就大打折扣了,而使用document_createDocu ...
- 1、eureka注册中心单机
Spring Cloud 2.x系列之 eureka注册中心单机 一.简介 Spring Cloud Eureka是Spring Cloud Netflix项目下的服务治理模块.而Spring Clo ...
- 提交disable的Select值到后台
需求:界面上把select控件disable,然后将默认值传到后台 问题1:select disable: js中可以这样写: document.getElementById("provin ...
- ethtool---查看网卡
ethtool 命令详解 命令描述: ethtool 是用于查询及设置网卡参数的命令. 使用概要:ethtool ethx //查询ethx网口基本设置,其中 x 是对应网卡的编号,如et ...
- 【LeetCode】水题(刚开始重新刷题找感觉用的)
[9] Palindrome Number [Easy] 给一个数字,用不转化成字符串的方式判断它是否是回文. 先求数字长度,然后把数字的后半段做翻转(就是不断地取模,除10这种方式),然后判断前后半 ...
- element-ui中table渲染的快速用法
element-ui中对table数据的渲染有一些模板式的操作,基本按照模板渲染数据即可 基本模板样式如下 <el-table :data="studentData.rows" ...
- eclipse发布路径变更
但是其默认访问的目录是eclipse临时目录而非Tomcat目录, 建议双击tomcat進入配制界面Service Locations 修改选项为:Use Tomcat installation(ta ...