1、导入spring-test.jar 对于spring 3.2版本这个包是:
spring-framework-3.2.0.RELEASE-dist\libs\spring-test-3.2.0.RELEASE.jar
2、编写测试用例
下面这个例子有不完善的地方,它不能试用于所有情况,仅供参考!
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import cn.itcast.service.HelloService; //RunWith注解的参数是固定的 @RunWith(SpringJUnit4ClassRunner.class) // 指定配置文件位置,此时配置文件在src下. @ContextConfiguration(locations = "classpath:applicationContext.xml") public class HelloServiceTest { @Autowired//自动装配bean,注入需要测试的对象 private HelloService helloService; @Test // 测试 public void demo2() { helloService.sayHello(); } @Test // 没有整合spring的测试 public void demo1() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml"); HelloService helloService = (HelloService) applicationContext .getBean("helloService"); helloService.sayHello(); } }
相关推荐
Spring整合Junit框架进行单元测试Demo 详细参考: http://blog.csdn.net/stemq/article/details/53291919
SpringBoot中整合Junit测试示例源码
该资源包含了spring整合单元测试Junit开发包spring-test-4.2.4.RELEASE.jar
springboot整合junit测试用例demo
spring整合Junit4所依赖的jar
主要介绍了SSM框架中测试单元的使用 spring整合Junit过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring框架对JUnit进行了整合,可以方便地在Spring环境中进行单元测试。 接管JUnit资源是指Spring框架为了方便进行单元测试,在测试类中提供了自动装配和依赖注入的功能,使得测试类能够轻松地使用Spring容器中的...
SpringBoot实战:整合jUnit测试框架一、前言二、添加依赖三、简单业务代码四、创建测试类五、运行测试类1.单个方法或类的测试2.运行整个项目的测试方法2.1.使用IDEA运行整个项目的测试类2.2.使用maven命令运行整个...
Spring整合Junit测试:Spring整合Junit测试时需要的jar包.
Spring整合Junit测试:Spring整合Junit测试使用的时候所需啊哟的jar包是 spring-test-3.2.0.RELEASE.jar
spring+hibernate整合列子,用junit测试增删改查都实现(MySQL包含表)
springboot整合junit进行单元测试的项目代码(b站黑马程序员同步代码)
对JUNIT等测试框架的简单封装 这两天做Web开发,发现通过Spring进行对象管理之后,做测试变得复杂了。因为所有的Bean都需要在...于是想起Spring有一个测试框架,能够整合JUnit进行测试,于是便拿出来试试~
主要介绍了Springboot整合junit过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring整合Junit测试时所需要的jar包。 spring-test-3.2.3.RELEASE.jar
3.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 (特别注意:Spring3.0里不在提供对jotm的封装,spring-tx里没有JotmFactoryBean.class,我在jar里添加了类) 2)Demo 导入说明: 1.Eclipse ...
本章学习目标 Spring 框架简介 SpringIOC 的概念和作用 工厂模式设计一个简单的IOC 容器 SpringIOC 的XML 方式HelloWorld SpringIOC 的XML 方式创建对象配置细节 ... Spring 整合Junit 简化测试类编写
结合spring 单元测试需要的jar包,Spring整合Junit测试,希望对大家有帮助,谢谢啊!
整合最新SSH项目jar包:含log4j,junit测试,json,hib4,spring4,struts2.3.15,c3p0数据源
该资源中包含SSH框架整合中spring框架所需要...(3)Spring整合JUnit测试包 (4)AOP核心包(4个包) (5)JDBC模板和事务核心包(spring-jdbc|spring-tx) (6)Spring整合Hibernate核心包 (7)Spring整合Struts2核心包