Junit4测试框架与Spring集成测试
配置测试框架的测试基类,防止多次初始化Spring容器,测试类只需要继承基类即可
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {"classpath:SpringConfig.xml", "classpath:Spring-MVC.xml", "classpath:MyBatis.xml"}) @Transactional(transactionManager = "dataSourceTransactionManager") @Rollback(value = true) public class BaseTest { @Rule public TestWatcher testWatcher = new TestWatcher() {
@Override protected void starting(Description description) {
System.out.println(">>>>>>>>>>> " + description.getDisplayName() + " Starting......."); }
@Override protected void succeeded(Description description) { System.out.println(">>>>>>>>>>> " + description.getDisplayName() + " Succeeded......."); }
@Override protected void failed(Throwable e, Description description) { System.out.println(">>>>>>>>>>> " + description.getDisplayName() + " >>>>>> Failed <<<<<<"); } }; }
|