通过Spring提供的测试基类AbstractJUnit4SpringContextTests,可以将Spring容器和Junit4测试框架整合。

在测试类中,@ContextConfiguration用于指定Spring的配置文件,@Autowired将Spring容器中的Bean注入测试类中。在测试方法前通过Junit4的@Test注解即可将方法标注为测试方法。

如:

@ContextConfiguration(locations={“classpath:test1/applicationContext.xml”})
public class TestAgcyCompany extends AbstractJUnit4SpringContextTests {
@Autowired
AgencyCompanyService agencyCompanyService;

@Test public void TestUPDATE_AGENCYCOMPANY_ENABLE(){
boolean is = agencyCompanyService.updateAgencyCompanyDisable(user, powerId, agencyCompany);
System.out.println(is);
}

}

更多:http://www.javaxxz.com/thread-67114-1-1.html

posted on 2013-01-15 12:54  Java学习者  阅读(261)  评论(0编辑  收藏  举报