Junit(手动/自动)加载
ssm中测试service层数据




Junit手动加载配置文件
package com.oukele.bookshop_ssm.service; import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class BookServiceTempTest { static ClassPathXmlApplicationContext context; @BeforeClass
public static void init(){
//初始化spring ,让其创建容器,实例化对象
context = new ClassPathXmlApplicationContext("spring_root.xml");
} @Before
public void setUp() throws Exception {
} @After
public void tearDown() throws Exception {
} @Test
public void listAll() {
//调用service层里 listAll() 方法 拿到数据
// 从spring 容器 中 ,取出被spring初始化好的对象
BookService bean = context.getBean(BookService.class);
System.out.println(bean.listAll()); } @Test
public void getBookName() {
} @Test
public void insert() {
} @Test
public void update() {
} @Test
public void insert_log() {
}
}

Junit自动加载配置文件
package com.oukele.bookshop_ssm.service; 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.SpringRunner; @RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:spring_root.xml")
public class BookServiceTempTest { @Autowired
private BookServiceTemp bookServiceTemp; @Test
public void listAll() {
System.out.println(bookServiceTemp.listAll());
} @Test
public void getBookName() {
} @Test
public void insert() {
} @Test
public void update() {
} @Test
public void insert_log() {
}
}

如果 使用 自动加载 有出现这个报错(导入 spring-test jar包)

图示:

<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
Junit(手动/自动)加载的更多相关文章
- Junit手动/自动加载spring配置文件
分配置文件在classpath下和web-inf下两种情况的加载: ApplicationContext context = new FileSystemXmlApplicationContext(& ...
- angularjs自动加载和手动加载
(一)自动加载 ng-app是angular的一个指令,代表一个angular应用(也叫模块).使用ng-app或ng-app=""来标记一个DOM结点,让框架会自动加载.也就是说 ...
- 关于thinkPHP中的自动加载和手动导入
首先先讲自动加载: 前提:你的第三方类库要满足(1)符合命名规范和后缀的类库(2)使用命名空间,命名空间和路径一致的类库 (1)在ThinkPHP目录下的library目录下的每一个子目录都是一个根命 ...
- Composer概述及其自动加载探秘
composer概述 一开始,最吸引我的当属 Composer 了,因为之前从没用过 Composer . Composer 是PHP中用来管理依赖关系的工具,你只需在自己的项目中声明所依赖的外部工具 ...
- Composer实现PHP中类的自动加载
本篇博客承接上一篇,学习一下Composer实现的PHP的类的自动加载方式.首先说明一下,Composer是PHP针对PHP语言的第三方的依赖管理工具,将工程所用到的依赖文件包含在composer.j ...
- PHP中类自动加载的方式
最近在学习composer,发现从接触PHP到现在已经遇到了三种关于PHP中类的自动加载方式,这其中包括PHP自带的类的自动加载方式.PHP的第三方的依赖管理工具composer的加载方式以及PHP的 ...
- PHP自动加载__autoload的工作机制
PHP自动加载__autoload的工作机制 PHP的懒加载lazy loading 在 2011年11月12日 那天写的 已经有 4559 次阅读了 感谢 参考或原文 服务器君一共花费了 ...
- PHP的类自动加载机制
在PHP开发过程中,如果希望从外部引入一个class,通常会使用include和require方法,去把定义这个class的文件包含进来. 这个在小规模开发的时候,没什么大问题.但在大型的开发项目中, ...
- thinkphp学习笔记9—自动加载
原文:thinkphp学习笔记9-自动加载 1.命名空间自动加载 在3.2版本中不需要手动加载类库文件,可以很方便的完成自动加载. 系统可以根据类的命名空间自动定位到类库文件,例如定义了一个类Org\ ...
随机推荐
- Git 的配置
一般配置用户层面配置 Git 的配置从上到下分三层 system/global/local,使用三个不同参数进行设置,每个层次的配置存储在不同的位置, 1)./etc/gitconfig 文件:包含了 ...
- 菜鸟系列docker——docker容器(7)
docker 容器 1. docker 守护进程daemon Daemon是Docker的守护进程,Docker Client通过命令行与Docker Damon通信,完成Docker相关操作,Doc ...
- Minimum Cost For Tickets
In a country popular for train travel, you have planned some train travelling one year in advance. ...
- 免费ip共享库
分享一个免费的ip地址库查询,同时支持ipv4和ipv6查询,提供api接口.官网地址:https://www.calpha.club/ 希望可以帮助运维朋友们. python 2.7实例# -*- ...
- SQL Server 数据备份存储过程
原文:SQL Server 数据备份存储过程 今天开园,分享一下我一直在使用的数据备份存储过程,欢迎转载!!! ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- 【LOJ】#2985. 「WC2019」I 君的商店
LOJ#2985. 「WC2019」I 君的商店 一道很神仙的题啊QAQ 居然是智商题--不是乱搞或者是大数据 我们可以用2N问出一个最大值是1 然后对于任意两个值\(x + y\)和\(a\)比较 ...
- Spring4学习回顾之路02—IOC&DI
IOC&DI介绍 ●IOC:(Inversion of Control) :控制反转(反向获取资源) 其思想是反转资源获取的方向.传统的资源上查找方式要求组件向容器发起请求查找资源,作为回应, ...
- uname、hostname命令
一.uname:显示系统信息. 语法: uname [OPTION] ... 描述 打印某些系统信息. 没有选项,与-s相同. -a,--all ...
- MySQL5.7,MySQL8 pfs,sys库使用
MySQL5.7中performance和sys schema中的监控参数解释 在MySQL5.7中,performance schema有很大改进,包括引入大量新加入的监控项.降低占用空间和负载,以 ...
- 《深入理解 Java 虚拟机》学习 -- 垃圾收集器
<深入理解 Java 虚拟机>学习 -- 垃圾收集器 1. Serial 收集器(新生代) 含义: 单线程收集器. 缺点: 进行垃圾收集时,必须暂停其他所有的工作线程. 优点: 简单而高效 ...