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

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:74日期: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、導(dǎo)入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(指定配置文件)

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

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 99色在线| 中文字幕在线观看第一页 | 一级做a爱片性色毛片 | 午夜精品免费 | 国产高清网站 | 一区二区三区四区精品 | 美女免费视频网站 | 日韩一区精品 | 国产福利在线 | 精品黄色片 | 亚洲午夜在线 | 亚洲天堂偷拍 | 一级片在线 | 午夜成人在线视频 | 国产伦精品一区二区三区视频网站 | 91禁蘑菇在线看 | 欧美精品在线视频 | 国产网站视频 | 青青五月天 | 欧美精品亚洲精品 | 一区二区免费在线观看 | 欧美aaaaa| 欧美日韩在线看 | 国产日韩综合 | 谁有毛片网址 | 在线观看黄色av | 久久中文视频 | 中国一级毛片免费看 | 国产精品999999 | 久久艳片www.17c.com| 欧美在线观看一区 | 成 人 黄 色 片 在线播放 | 欧美激情综合 | 深夜福利在线播放 | 91成人免费视频 | 欧美视频在线观看一区 | 一区二区三区四区精品 | 久久久久久中文字幕 | 日韩精品一区在线观看 | 二区在线观看 | 欧美69视频|