Spring 提供便捷的測試,很是方便整合Junitspring
導入 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配置文件,將須要測試對象 注入到 測試類中,在測試方法中 直接使用對象便可app