第一种方式: //spring整合junit4 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; /** * Created by staunch on 2016-07-12. * version:v1.0 * instruction:初始版本 */ @RunWith(SpringJUnit4ClassRunner.class) // 整合 @ContextConfiguration(locations="classpath:config/applicationContext.xml") // 加载配置 public class AdvisorServiceTest { @Autowired private //注入测试依赖 @Test public void testCheckStudentInfo() throws Exception { //测试代码 } } 第二种方式: //Spring+testNG import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.List; /** * Created by staunch on 2016-06-29. * version:v1.0 * instruction:初始版本 */ @ContextConfiguration(locations = {"/config/applicationContext.xml"}) public class AdvisorMapperTest extends AbstractTestNGSpringContextTests{ @Autowired //注入的测试依赖 @Test public void testBatchInsertDiscussion() throws Exception { //测试代码 } ); }
相关推荐
Spring Boot单元测试
spring单元测试包spring单元测试包spring单元测试包spring单元测试包spring单元测试包
该资源包含了spring整合单元测试Junit开发包spring-test-4.2.4.RELEASE.jar
Junit4+Spring2.5单元测试代码示例同时也适用注解注入的形式测试(前提要导好测试的包哦,包MyEclipce自带了)
Spring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot中的单元测试.pdfSpring Boot...
NULL 博文链接:https://caerun.iteye.com/blog/1108226
spring mvc的简单单元测试:,详细请参考:http://blog.csdn.net/xiejx618/article/details/21201007
通过Spring集成单元测试,以后测试service层内容时,就不用getBean()来获得Service层对象了
30-Spring Boot单元测试1
主要介绍了Spring Boot 单元测试和集成测试实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Struts+Spring框架下的单元测试
通过java配置的方式搭建了一个基本的web项目,主要用于单元测试示例,使用了spring支持h2内存数据库,不需要额外安装数据库,可以测试controller层、service层
这是一个测试事务管理的例子,希望对你们有所帮助,项目里子是在myeclipse中的maven创建的。myeclipse应该可以直接运行。
Spring_单元测试_2种写法
Struts2+Spring+hibernate中对action的单元测试环境搭建[总结].pdf
基于Spring的JUnit4单元测试
Struts2 Spring 框架整合 单元测试 Action和Service http://blog.csdn.net/fansunion/
Struts+Spring框架下的单元测试[总结].pdf
举例spring security的单元测试,详细参考http://blog.csdn.net/xiejx618/article/details/48792543
使用Idea工具建立的Maven工程,整合Spring和MyBatis,成功通过单元测试