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

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-08-10
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案