在spring没有整合Junit之前,是这样测试的:

spring整合Junit单元测试

每测试一个单元都要new ClassPathXmlApplicationContext实现类对象,然后通过ApplicationContext的getBean方法去获得对象,是不是很麻烦呢?

现在我们要把spring整合Junit进来,方便我们的单元测试:

导包:spring-test包

spring整合Junit单元测试

spring整合Junit单元测试

然后在测试类中使用两个注解:

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext.xml")

即可

spring整合Junit单元测试

是不是方便多了呢!

相关文章:

  • 2021-12-23
  • 2021-12-12
  • 2021-04-26
  • 2021-12-04
  • 2021-07-24
  • 2021-06-20
  • 2021-12-19
猜你喜欢
  • 2021-10-07
  • 2021-04-20
  • 2021-08-11
  • 2021-11-08
  • 2021-10-01
  • 2021-12-18
  • 2021-11-20
相关资源
相似解决方案