麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

junit4 單元測(cè)試

2019-11-14 21:03:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
junit4 單元測(cè)試

1.所需jar包

下載地址:http://search.maven.org/

搜索junit-4.12-beta-1

  aspectjweaver-1.8.2

  sPRing-test-4.0.6.RELEASE

2.3中測(cè)試形式

(1)最古老的

package sy.test;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.context.applicationContext;import org.springframework.context.support.ClassPathxmlApplicationContext;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import sy.model.User;import sy.service.IUserService;//@RunWith(SpringJUnit4ClassRunner.class)//@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-mybatis.xml"})public class TestMybatis {        //使用test注解    @Test    public void test1(){        //讀取配置文件,如有多個(gè),用逗號(hào)隔開        ApplicationContext ctf =                 new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"});        //獲取userService實(shí)例        IUserService userService = (IUserService) ctf.getBean("userService");        User user = userService.getUserById("0");        System.out.println(user);    }    }

  (2).如果有多個(gè)test,則spring每次都要去加載讀取上下文,很浪費(fèi)資源,因此

package sy.test;import org.junit.Before;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import sy.model.User;import sy.service.IUserService;//@RunWith(SpringJUnit4ClassRunner.class)//@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-mybatis.xml"})public class TestMybatis {        private IUserService userService;    private ApplicationContext ctf;    @Before    public void before(){        ctf = new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"});         userService = (IUserService) ctf.getBean("userService");    }        //使用test注解    @Test    public void test1(){        User user = userService.getUserById("0");        System.out.println(user);    }        //使用autowired注解    @Autowired    public void setUserService(IUserService userService) {        this.userService = userService;    }        }

@Before注解會(huì)在所有test測(cè)試之前執(zhí)行

(3)spring與junit整合

package sy.test;import org.junit.Before;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import sy.model.User;import sy.service.IUserService;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-mybatis.xml"})public class TestMybatis {        private IUserService userService;        //使用test注解    @Test    public void test1(){        User user = userService.getUserById("0");        System.out.println(user);    }        //使用autowired注解    @Autowired    public void setUserService(IUserService userService) {        this.userService = userService;    }        }


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美成网 | 亚州成人在线观看 | 国产午夜亚洲精品 | 亚洲午夜电影 | 爽爽淫人网 | 久久91精品国产91久久yfo | 免费毛片免费看 | 国产 一区 精品 | 久久久久中精品中文字幕19 | 香蕉视频1024 | 91精品国产99久久久久久红楼 | 国产区二区 | 7m视频成人精品分类 | 操操插插 | 久久久久久中文字幕 | 久久精品国产一区二区电影 | 日本在线一区二区 | av电影在线网站 | 久久亚洲第一 | 日韩一级片毛片 | 国产欧美一区二区三区免费看 | 91精品国产一区二区三区动漫 | 成人国产免费观看 | 精品亚洲夜色av98在线观看 | 91久久国产露脸精品免费 | 国产精品呻吟 | 亚洲第一综合 | 福利在线小视频 | 性大片1000免费看 | 一级毛片免费观看在线 | 男女一边摸一边做羞羞视频免费 | 亚洲综合视频一区 | 精品中文字幕在线播放 | 国产精品久久久久久久久久妇女 | 欧美性生活久久 | 亚洲午夜在线观看 | 黄色大片在线免费观看 | 日日天日日夜日日摸 | 国产精品一区二区三区在线 | 国产1区2区3区中文字幕 | 国产精品免费观在线 |