Spring Framework,Spring 整合junit

 2023-10-05 阅读 33 评论 0

摘要:junit需要是4.12版本以上 <dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.0.2.RELEASE</version></dependency><dependency><groupId>junit</groupId&g

junit需要是4.12版本以上

        <dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.0.2.RELEASE</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency>
/*** 使用Junit單元測試:測試我們的配置* Spring整合junit的配置*      1、導入spring整合junit的jar(坐標)*      2、使用Junit提供的一個注解把原有的main方法替換了,替換成spring提供的*             @Runwith*      3、告知spring的運行器,spring和ioc創建是基于xml還是注解的,并且說明位置*          @ContextConfiguration*                  locations:指定xml文件的位置,加上classpath關鍵字,表示在類路徑下*                  classes:指定注解類所在地位置**   當我們使用spring 5.x版本的時候,要求junit的jar必須是4.12及以上*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfiguration.class)//注解形式
//@ContextConfiguration(locations = "classpath:bean.xml")//xml形式
public class AccountServiceTest {}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/115817.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息