Spring集成JUnit测试

  1. 程序中有Junit环境.
  2. 导入一个jar包.spring与junit整合jar包.
  • spring-test-3.2.0.RELEASE.jar
  1. 测试代码:
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(locations = "classpath:applicationContext.xml")
  3. public class HelloServiceTest {
  4. @Autowired
  5. private HelloService helloService;
  6. @Test
  7. public void demo1 () {
  8. helloService.sayHello();
  9. }
  10. }

这种方式下会运行整个周期,包括销毁的生命阶段





posted @ 2016-10-21 11:10  小坨男  阅读(197)  评论(0编辑  收藏  举报