Spring+Junit4進行接口測試實例代碼
更新時間:2018年01月31日 09:26:56 作者:Wind_365
這篇文章主要介紹了Spring+Junit4進行接口測試實例代碼,涉及pom.xml、bean的配置,以及接口測試代碼等相關(guān)內(nèi)容,小編覺得還是挺不錯的,這里分享給大家,需要的朋友可以參考下
本文研究的主要是Spring+Junit4進行接口測試的一個相關(guān)實例,具體實現(xiàn)代碼如下。
1.配置pom.xml
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency>
2.配置bean
testInterface可以進行手動配置或自動掃描
手動配置
spring配置文件配置:
<bean id="testInterface" class="com.xxx.TestInterfaceImpl"> </bean>
自動掃描
接口實現(xiàn)類中配置
@Component
public class TestInterfaceImpl implements TestInterface {
spring配置文件配置
<context:annotation-config/> <context:component-scan base-package="com.xxx.servlet"> </context:component-scan>
3.編寫接口測試代碼
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class Test {
@Resource
TestInterface testInterface;
@Test
public void test1(){
testInterface.test1(1,2);
}
總結(jié)
以上就是本文關(guān)于Spring+Junit4進行接口測試實例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
基于java查找并打印輸出字符串中字符出現(xiàn)次數(shù)
這篇文章主要介紹了基于java查找并打印輸出字符串中字符出現(xiàn)次數(shù),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-11-11
SpringBoot+WebSocket實現(xiàn)多人在線聊天案例實例
本文主要介紹了SpringBoot+WebSocket實現(xiàn)多人在線聊天案例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02
mybatis中<if>標簽bool值類型為false判斷方法
這篇文章主要給大家介紹了關(guān)于mybatis中<if>標簽bool值類型為false判斷方法,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用mybatis具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

