junit4 的使用 顺便理解ClassPathXmlApplicationContext的使用


工作中,需要给同事在dao层写个方法,写完后,只能用junit测试,如是学习了junit4的使用。

先用eclipse引入junit4相关包,然后写个类如下,就行了。

public class Test extends TestCase{
	
	private IDiscountDao discountDao;

	@Override
	protected void setUp() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		discountDao =context.getBean(IDiscountDao.class);
	}
	
	public void test1(){
		DiscountInfo info = discountDao.getDiscForZhuanban("036596782c9611e2b12d00215e6e7653");
		System.out.println(info);
	}
}

 框架用的是springmvc + ibatis ,各种类都是注解的。

discountDao =context.getBean(IDiscountDao.class);这样取到要测试的dao类。

ClassPathXmlApplicationContext("applicationContext.xml")这个表示取类路劲下的applicationContext.xml,即web-info/classes/下的applicationContext.xml文件,
也就是源码中src下面的applicationContext.xml文件。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM