使用junit4测试Spring

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配置文件,将需要测试对象 注入到 测试类中,在测试方法中 直接使用对象即可

posted @ 2016-12-14 14:42  dorothyorsusie  阅读(176)  评论(0编辑  收藏  举报