junit4 的使用 顺便理解ClassPathXmlApplicationContext的使用
生活随笔
收集整理的這篇文章主要介紹了
junit4 的使用 顺便理解ClassPathXmlApplicationContext的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
工作中,需要給同事在dao層寫個方法,寫完后,只能用junit測試,如是學習了junit4的使用。
先用eclipse引入junit4相關包,然后寫個類如下,就行了。
public class Test extends TestCase{private IDiscountDao discountDao;@Overrideprotected 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文件。
轉載于:https://www.cnblogs.com/xiongjinpeng/archive/2013/01/10/2854103.html
總結
以上是生活随笔為你收集整理的junit4 的使用 顺便理解ClassPathXmlApplicationContext的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简明Linux命令行笔记:sort
- 下一篇: github 使用总结-----转