av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Junit寫法及與spring整合過程詳解

瀏覽:75日期:2023-09-01 15:34:53

junit之前的寫法:

//在Before中注入service類private IUserService userService; @Beforepublic void setUp() throws Exception {//使用xml的方式ApplicationContext applicationContext = new ClassPathXmlApplicationContext('applicationContext.xml');//使用注解的方式ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);userService = applicationContext.getBean(IUserService.class); }

Spring與junit整合:

不需要手動創(chuàng)建Spring容器, 自動把bean注入到測試類

1、導入spring-test的依賴, 需要junit

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.3.RELEASE</version></dependency>

2、在測試類使用spring-test的注解

@RunWith(class)

@ContextConfiguration(指定配置文件)

//測試類運行的環(huán)境,在spring環(huán)境下運行,在測試類, 注入Spring容器的bean@RunWith(SpringJUnit4ClassRunner.class)//在創(chuàng)建spring容器時,指定加載哪個配置文件 - - 相當于之前的手動獲取對象@ContextConfiguration('classpath:applicationContext.xml')public class UserServiceImplTest { @Autowired //注入IUserService private IUserService userService; @Test public void testFindUserById() { userService.findUserById(2); }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Spring
相關文章:
主站蜘蛛池模板: 九一九色国产 | 亚洲精品视频在线播放 | 毛片视频网站 | 中文文字幕文字幕高清 | 97caoporn| 欧美片网站免费 | 国产午夜小视频 | 一区二区日韩 | 亚洲成人精品 | 狠狠操狠狠操 | 欧美不卡 | 亚洲成人免费av | 午夜激情网 | 欧美久久久久久久久 | 久草这里只有精品 | 色爽视频| 青青在线视频 | av不卡在线播放 | 成人在线视频播放 | 国产精品久久久一区二区三区 | 秋霞一区| 久久久久久国产精品 | 欧美一级在线观看 | 一级片久久久 | 国产一区在线看 | 天天综合网站 | 欧美日韩四区 | 秋霞午夜鲁丝一区二区老狼 | 专业操老外 | 色婷婷国产精品综合在线观看 | 亚洲国产欧美在线 | 国产精品美女久久久久av爽 | 日本免费毛片 | 精品三级在线观看 | 精品aaa| 免费av毛片 | 国产区视频在线观看 | 色污污| 日韩天堂在线 | 天堂在线www | 成人毛片在线播放 |