搭建Spring环境(自行搭建):

@RunWith注解指定使用springJunit的测试运行器

@ContextConfiguration注解指定测试用的spring配置文件的位置

import static org.junit.Assert.*;
import javax.annotation.Resource;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class test
{
@Resource
RelationEventDao an; @BeforeClass
public static void setUpBeforeClass() throws Exception
{
System.out.println("setUpBeforeClass");
} @AfterClass
public static void tearDownAfterClass() throws Exception
{
System.out.println("tearDownAfterClass");
} @Before
public void setUp() throws Exception
{
System.out.println("setUp");
} @After
public void tearDown() throws Exception
{
System.out.println("tearDown");
} @Test
public void testTest()
{ try
{
assertNotNull(an.Event("测试的事件"));
}
catch (ZhiWeiException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} } }

  

在Spring里进行单元测试Junit的更多相关文章

  1. Spring注解AOP及单元测试junit(6)

    2019-03-10/20:19:56 演示:将xml配置方式改为注解方式 静态以及动态代理推荐博客:https://blog.csdn.net/javazejian/article/details/ ...

  2. 【Spring】Junit加载Spring容器作单元测试(整理)

    [Spring]Junit加载Spring容器作单元测试 阅读目录 >引入相关Jar包 > 配置文件加载方式 > 原始的用法 > 常见的用法 > 引入相关Jar包 一.均 ...

  3. Spring Boot干货系列:(十二)Spring Boot使用单元测试(转)

    前言这次来介绍下Spring Boot中对单元测试的整合使用,本篇会通过以下4点来介绍,基本满足日常需求 Service层单元测试 Controller层单元测试 新断言assertThat使用 单元 ...

  4. Spring Boot学习——单元测试

    本随笔记录使用Spring Boot进行单元测试,主要是Service和API(Controller)进行单元测试. 一.Service单元测试 选择要测试的service类的方法,使用idea自动创 ...

  5. Java学习——单元测试JUnit

    Java学习——单元测试JUnit 摘要:本文主要介绍了什么是单元测试以及怎么进行单元测试. 部分内容来自以下博客: https://www.cnblogs.com/wxisme/p/4779193. ...

  6. Springboot单元测试Junit深度实践

    Springboot单元测试Junit深度实践 前言 单元测试的好处估计大家也都知道了,但是大家可以发现在国内IT公司中真正推行单测的很少很少,一些大厂大部分也只是在核心产品推广单测来保障质量,今天这 ...

  7. Spring Boot 的单元测试

    Spring Boot 的单元测试 引入依赖 testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-tes ...

  8. SpringBoot与单元测试JUnit的结合

    有些人认为,写单元测试就是在浪费时间 ,写完代码,依然还是能够进行测试的.但是,还是建议写单元测试的,可以让你的条理更加清晰,而且当某个功能出现问题时,可能通过单元测试很容易的定位和解决问题.本文主要 ...

  9. 详解intellij idea搭建SSM框架(spring+maven+mybatis+mysql+junit)(下)

    在上一篇(详解intellij idea 搭建SSM框架(spring+maven+mybatis+mysql+junit)(上))博文中已经介绍了关于SSM框架的各种基础配置,(对于SSM配置不熟悉 ...

随机推荐

  1. WCF 、Web API 、 WCF REST 和 Web Service 的区别

    WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...

  2. linux虚拟机上不了网--桥接方式--问题一直未解决

    转载的:可是自己的虚拟机就是上不了网,无线网卡该配的也配了还是不行,如果真有台物理机器就行了,省了好多事:但是模拟性能时肯定不行了:有人知道是什么原因不? 虚拟机网络模式 无论是vmware,virt ...

  3. AngularJs的UI组件ui-Bootstrap---tabs控件

    tabs控件使用uib-tabset指令和uib-tab指令,效果是这样的: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo ...

  4. 数据终端设备与无线通信模块之间串行通信链路复用协议(TS27.010)在嵌入式系统上的开发【转】

    转自:http://blog.csdn.net/hellolwl/article/details/6164449 目录(?)[-] 协议介绍 模块协议介绍 1            命令包格式 2   ...

  5. Android setVisibility()

    android view setVisibility(): 有三个参数:Parameters:visibility One of VISIBLE, INVISIBLE, or GONE,想对应的三个常 ...

  6. proxifier 3.29 key

    Proxifier 3.29 serial key :-   [Use only One ]  (Standard Edition Keys) 5EZ8G-C3WL5-B56YG-SCXM9-6QZA ...

  7. tensorflow安装日志(PIP)

    最近刚刚接触深度学习,安装一下tf 环境:华硕Z170主板.i7 6700k.GTX1070.Ubuntu16.04.Python2.7 在这之前先装好了cuda8.0.cudnn5.0.caffe整 ...

  8. 微信小程序组件-----城市切换

    直接上地址,有需要的直接下载,使用: https://github.com/chenjinxinlove/citySelect

  9. git学习——git理解和仓库的创建

    一.git用的3个工作的状态的理解. 1. 工作区 workspace(modified); 2. 暂存区 stage(staged) ; 3. git本地仓库 repository(commited ...

  10. spring-listener&spring-task注解版本

    1.spring-listener: a) import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextLi ...