• spring测试父类,使用junit-4.4.jar,spring-test.jar


    @ContextConfiguration(locations = "classpath:conf/applicationContext.xml")
    @RunWith(SpringJUnit4ClassRunner.class)
    @Transactional
    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
    public abstract class AbstractTestCase extends
    		AbstractTransactionalDataSourceSpringContextTests {
    
    }
    


    将配置项都写在父类中,测试子类继承该AbstractTestCase类,测试的时候,不会导致数据库数据污染,因为继承AbstractTransactionalDataSourceSpringContextTests每次数据库操作完成之后都会回滚。

    例如:

    public class TransFlowServiceTests extends AbstractTestCase {
    	@Autowired
    	TransFlowService transFlowService;
    	
    	@Test
    	public void testQueryTransFlow() {
    		Map map = new HashMap();
    		PageBean pb = new PageBean(1, 20, 10);
    		map.put("pb", pb);
    		List<TransFlow> lis = transFlowService.queryTransFlow(map);
    		for (TransFlow tf : lis) {
    			System.out.println(tf.getOrderNo() + "-" + tf.getStatus() + "-" + tf.getStatusView() + "-" + tf.getOrderTime() + "-" + tf.getOrderTimeView());
    		}
    	}
    
    	@Test
    	public void testGetTransFlowCount() {
    		Map map = new HashMap();
    		PageBean pb = new PageBean(1, 20, 10);
    		map.put("pb", pb);
    		int i = transFlowService.getTransFlowCount(map);
    		System.err.println("i="+i);
    	}
    	
    	@Test
    	public void testGetTransFlowNum() {
    		int j = transFlowService.getTransFlowNum();
    		System.out.println("j="+j);
    	}
    
    	@Test
    	public void testUpdateTransFlowStatus() {
    		int k = transFlowService.updateTransFlowStatus();
    		System.err.println("k="+k);
    	}
    
    }
    
  • 相关阅读:
    补货知识要点解析
    【解析】ABC与CVA分析法
    【进阶】安全库存与动态平衡
    【知识】可用于仓储数据分析的4类方法
    浅析VMI(供应商库存管理)的实施条件与原则
    补货分类与策略要点
    仓库运营效率提升手册(简版)
    WinForm嵌入Web网站 逝年
    如何将本地项目上传到gitlab IT
    oracle数据库exp和imp的使用
  • 原文地址:https://www.cnblogs.com/simpledev/p/3820819.html
Copyright © 2020-2023  润新知