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. }

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





原文地址:https://www.cnblogs.com/oneNightStand/p/5a386d3785ac76f4588770e6057e0905.html