idea intellij对Spring进行单元测试
1、加入Junit4及SpringJUnit4支持
- <!-- junit -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- spring-test -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- </dependency>
2、创建测试类
(wins:右键菜单------->转到(G)------->测试(E) 可快捷在test包,相同目录下建立相应的测试类)
(ios:IntelliJ IDEA提供了一个快捷操作Cmd + Shift + T作为类和测试之间的导航。同时允许用户在那里创建一个测试类。)
3、生成的代码如下:
- package net.wll.web.service.impl;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class DAreasServiceImplTest {
- @Test // 注:我自己的和这里有一点小差别,即前面没有test而是和待测试方法一模一样
- public void testSelectSubDistricts() throws Exception {
- }
- @Test
- public void testSelectSubDistricts0() throws Exception {
- }
- }
4、增加Spring-test支持
- package net.xuele.activity.service.impl;
- import net.xuele.activity.domain.DAreas;
- import net.xuele.activity.service.DAreasService;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import javax.annotation.Resource;
- import java.util.List;
- @RunWith(SpringJUnit4ClassRunner.class)
- /** 注入相关的配置文件:可以写入多个配置文件 **/
- @ContextConfiguration(locations={"classpath:META-INF/spring/application-services.xml",
- "classpath:META-INF/spring/applicationContext-persist.xml"
- })
- public class DAreasServiceImplTest {
- @Resource
- private DAreasService dAreasService;
- @Test
- public void testSelectSubDistricts0() throws Exception {
- List<DAreas> dAreases = this.dAreasService.selectSubDistricts0();
- System.out.println(dAreases.size());
- }
- }
- 转载自:https://blog.csdn.net/xcwll_sina/article/details/49277645
idea intellij对Spring进行单元测试的更多相关文章
- Spring之单元测试
引言 是否在程序运行时使用单元测试是衡量一个程序员素质的一个重要指标.使用单元测试既可以让我检查程序逻辑的正确性还可以让我们减少程序测试的BUG,便于调试可以提高我们写程序的效率.以前我们做单元测试的 ...
- Spring Boot单元测试(Mock)
Spring Boot单元测试(Mock) Java个人学习心得 2017-08-12 16:07 Mock 单元测试的重要性就不多说了,我这边的工程一般都是Spring Boot+Mybatis(详 ...
- 框架:Intellij搭建Spring框架
第二章.Intellij搭建Spring框架 前提条件:jdk.jre已经安装完成 方法一.intellij下载jar 附:自带的jar的版本为4.3[2018/11/22] 第一步:选择File&g ...
- Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题
问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.
- 【Spring Boot&&Spring Cloud系列】使用Intellij构建Spring Boot和Mybatis项目
一.创建项目 1.File->New->Project->spring initializer 2.勾选Web SQL Template Engines 3.项目生成之后,点击add ...
- Spring MVC学习总结(1)——Spring MVC单元测试
关于spring MVC单元测试常规的方法则是启动WEB服务器,测试出错 ,停掉WEB 改代码,重启WEB,测试,大量的时间都浪费在WEB服务器的启动上,下面介绍个实用的方法,spring MVC单元 ...
- IntelliJ IDEA使用JUnit单元测试
转载:https://www.cnblogs.com/huaxingtianxia/p/5563111.html 前言 单元测试的基本使用 一.环境配置 使用idea IDE 进行单元测试,首先需要安 ...
- Spring Boot 单元测试示例
Spring 框架提供了一个专门的测试模块(spring-test),用于应用程序的单元测试. 在 Spring Boot 中,你可以通过spring-boot-starter-test启动器快速开启 ...
- spring的单元测试
如果spring 4.3.18这个版本的spring要使用junit,需要使用junit的junit-4.12之上的版本.使用这个版本junit的时 候需要引入hamcrest-all的jar包.之前 ...
随机推荐
- multithreading coding
分类:公共资源问题.公交车问题 顺序:Qseater lab, bank, doctor [饭店] geust //yuec2 Yue Cheng package lab9; public abstr ...
- SAP ALV 修改数字需要添零问题
问题描述: 修改左列数字,如果想要输入3,那么要输3000,敲空格,才会在ALV里显示为3. 原因: 变量ERFMG引用的域类型小数点位置为3位,当输入数字1时,默认往前数3位,作为小数点位置,变成0 ...
- day 14 项目目录规范; time ; logging
import sys print(sys.modules) 程序一运行,解释器将里面的所有内容全部加载到内存 项目目录规范: 代码不可能全部只写在一个文件,十几万行代码,调整,修改都很不方便. 所 ...
- GridView(网格视图)+MotionEvent(触控事件)实现可以拖动排序的网格图
1.一触碰,就回调onInterceptTouchEvent(MotionEvent ev)事件,每次的触碰都只回调一次,接着只要还没有放手,就一直回调onTouchEvent(MotionEvent ...
- 使用swoole编写简单的echo服务器
server.php代码如下: <?php class EchoServer { protected $serv = null; public function __construct() { ...
- gearman管理工具GearmanManager的安装与使用
一.gearman自带了一个gearadmin工具 查看帮助信息 > gearadmin --help 查看状态 > gearadmin --status 查看worker信息 > ...
- redhat 5.6安装wireshark
mkdir -p /mnt/cdrom mount -t iso9660 /dev/cdrom /mnt/cdrom cd mnt/cdrom/Server rpm -ivh lm_sensors-- ...
- Vue 数组 字典 template v-for 的使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- gulp中pipe的作用和来源
gulp的pipe方法是来自nodejs stream API的,并不是gulp本身源码所定义的. 一.pipe方法的作用 pipe跟他字面意思一样只是一个管道 例如我有一堆文件 var s = gu ...
- hdu 1394(线段树) 最小逆序数
http://acm.hdu.edu.cn/showproblem.php?pid=1394 给出一列数组,数组里的数都是从0到n-1的,在依次把第一个数放到最后一位的过程中求最小的逆序数 线段树的应 ...