junit4 spring 便捷单元测试
2016-02-01 16:19
726 查看
Spring 提供便捷的测试,非常方便整合Junit
导入 spring-test-3.2.0.RELEASE.jar ---- 提供与Junit的整合
@RunWith(SpringJUnit4ClassRunner.class) // 整合
@ContextConfiguration(locations="classpath:applicationContext.xml") // 加载配置
public class HelloServiceTest {
@Autowired // 注入
private HelloService helloService;
@Test
public void testSayHello() {
helloService.sayHello();
}
}
通过配置 加载Spring配置文件,将需要测试对象 注入到 测试类中,在测试方法中 直接使用对象即可
导入 spring-test-3.2.0.RELEASE.jar ---- 提供与Junit的整合
@RunWith(SpringJUnit4ClassRunner.class) // 整合
@ContextConfiguration(locations="classpath:applicationContext.xml") // 加载配置
public class HelloServiceTest {
@Autowired // 注入
private HelloService helloService;
@Test
public void testSayHello() {
helloService.sayHello();
}
}
通过配置 加载Spring配置文件,将需要测试对象 注入到 测试类中,在测试方法中 直接使用对象即可
相关文章推荐
- Java线程:概念与原理
- Future和FutureTask区别
- springmvc下的基于token的防重复提交
- Spring MVC 教程,快速入门,深入分析
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 从头认识Spring-1.11 注入List或Set(这个例子比较体现代码复用)
- 简单介绍java Enumeration
- java类加载机制详解
- Java中String和byte[]的转换
- java对象和json对象之间互相转换
- 初识springmvc_01
- Spring定时任务的几种实现
- 在Eclipse上运行Spark(Standalone,Yarn-Client)
- spring mail demo
- Spring中任务调度cronExpression配置说明
- spring框架的IoC设计思想
- java对象克隆简单实现(可多级克隆)
- Java环境变量配置
- 本地方法(JNI)——数值参数与返回值
- 2016蓝桥杯假期任务之《矩形运算》