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(手动/自动)加载的更多相关文章

  1. Junit手动/自动加载spring配置文件

    分配置文件在classpath下和web-inf下两种情况的加载: ApplicationContext context = new FileSystemXmlApplicationContext(& ...

  2. angularjs自动加载和手动加载

    (一)自动加载 ng-app是angular的一个指令,代表一个angular应用(也叫模块).使用ng-app或ng-app=""来标记一个DOM结点,让框架会自动加载.也就是说 ...

  3. 关于thinkPHP中的自动加载和手动导入

    首先先讲自动加载: 前提:你的第三方类库要满足(1)符合命名规范和后缀的类库(2)使用命名空间,命名空间和路径一致的类库 (1)在ThinkPHP目录下的library目录下的每一个子目录都是一个根命 ...

  4. Composer概述及其自动加载探秘

    composer概述 一开始,最吸引我的当属 Composer 了,因为之前从没用过 Composer . Composer 是PHP中用来管理依赖关系的工具,你只需在自己的项目中声明所依赖的外部工具 ...

  5. Composer实现PHP中类的自动加载

    本篇博客承接上一篇,学习一下Composer实现的PHP的类的自动加载方式.首先说明一下,Composer是PHP针对PHP语言的第三方的依赖管理工具,将工程所用到的依赖文件包含在composer.j ...

  6. PHP中类自动加载的方式

    最近在学习composer,发现从接触PHP到现在已经遇到了三种关于PHP中类的自动加载方式,这其中包括PHP自带的类的自动加载方式.PHP的第三方的依赖管理工具composer的加载方式以及PHP的 ...

  7. PHP自动加载__autoload的工作机制

    PHP自动加载__autoload的工作机制 PHP的懒加载lazy loading 在 2011年11月12日 那天写的     已经有 4559 次阅读了 感谢 参考或原文   服务器君一共花费了 ...

  8. PHP的类自动加载机制

    在PHP开发过程中,如果希望从外部引入一个class,通常会使用include和require方法,去把定义这个class的文件包含进来. 这个在小规模开发的时候,没什么大问题.但在大型的开发项目中, ...

  9. thinkphp学习笔记9—自动加载

    原文:thinkphp学习笔记9-自动加载 1.命名空间自动加载 在3.2版本中不需要手动加载类库文件,可以很方便的完成自动加载. 系统可以根据类的命名空间自动定位到类库文件,例如定义了一个类Org\ ...

随机推荐

  1. 2019牛客暑期多校训练营(第七场)-C Governing sand

    题目链接:https://ac.nowcoder.com/acm/contest/887/C 题意:有n种树,给出每种数的高度.移除的花费和数量,求最小花费是多少使得剩下树中最高的树的数量占一半以上. ...

  2. SQL Pretty Printer for SSMS 很棒的格式化插件

    SQL Pretty Printer for SSMS 很不错的SQL格式化插件   写SQL语句或者脚本时,看到凌乱的格式就头大了,于是决心找一款SQL语句格式化的工具. 功夫不负有心人还真的被我找 ...

  3. BEGIN_MESSAGE_MAP和END_MESSAGE_MAP()

    这两个宏表示这个类的消息映射开始和结束,中间的宏定义定义了此类的所有的消息映射.前面的afx_msg void OnPaint():只是声明OnPaint()函数的一个消息处理函数,然后是OnPain ...

  4. 后缀数组 LCP--模板题

    题意: 给你S串和T串,用T串的所有前缀去匹配S串(匹配值是最长公共子串). 问你总值相加是多少. 思路: 先把两个S,T串倒过来,再拼接 S#T 合成一串,跑一下后缀数组 在排序好的rank里计算每 ...

  5. python基础(十二)--模块

    模块的导入方式 import os  调用时os.rename from os import rename #只导入的特定功能 调用时rename() from asynico.events impo ...

  6. js排列组合

    /* 全排列主要用到的是递归和数组的插入 arr: 需要排列的数组 第一步:从里面取一个,创建一个新的数组,形式为二维,例如arr = [1,2,3]; 取出3(没有特殊要求,随便取一个),放入 te ...

  7. 牛客 40E 珂朵莉的数论题

    大意: 给定$x,y$, 求第$x$小的最小素因子为$y$的数, 若答案>1e9输出0. 若$y>=60$, 可以暴力筛出1e9/60以内的答案. 否则容斥+二分算出答案. #includ ...

  8. luogu P2765 魔术球问题 (最小路径覆盖)

    大意:给定n根柱子, 依次放入1,2,3,...的球, 同一根柱子相邻两个球和为完全平方数, 求最多放多少个球. 对和为平方数的点连边, 就相当于求DAG上最小路径覆盖. #include <i ...

  9. Java8排序

    @Data @AllArgsConstructor @NoArgsConstructor public class Apple { private int wight; } 排序 List<In ...

  10. mysql创建表空间和用户

    创建表空间名 create database 空间名 default character set utf8 collate utf8_bin; 创建用户create user 用户名 identifi ...