您的位置:首页 > 编程语言 > Java开发

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配置文件,将需要测试对象 注入到 测试类中,在测试方法中 直接使用对象即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: