Spring+Junit4進(jìn)行接口測(cè)試實(shí)例代碼
本文研究的主要是Spring+Junit4進(jìn)行接口測(cè)試的一個(gè)相關(guān)實(shí)例,具體實(shí)現(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可以進(jìn)行手動(dòng)配置或自動(dòng)掃描
手動(dòng)配置
spring配置文件配置:
<bean id="testInterface" class="com.xxx.TestInterfaceImpl"> </bean>
自動(dòng)掃描
接口實(shí)現(xiàn)類中配置
@Component
public class TestInterfaceImpl implements TestInterface {
spring配置文件配置
<context:annotation-config/> <context:component-scan base-package="com.xxx.servlet"> </context:component-scan>
3.編寫接口測(cè)試代碼
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進(jìn)行接口測(cè)試實(shí)例代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
相關(guān)文章
Java線程池的幾種實(shí)現(xiàn)方法及常見問題解答
下面小編就為大家?guī)硪黄狫ava線程池的幾種實(shí)現(xiàn)方法及常見問題解答。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05
基于java查找并打印輸出字符串中字符出現(xiàn)次數(shù)
這篇文章主要介紹了基于java查找并打印輸出字符串中字符出現(xiàn)次數(shù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
SpringBoot+WebSocket實(shí)現(xiàn)多人在線聊天案例實(shí)例
本文主要介紹了SpringBoot+WebSocket實(shí)現(xiàn)多人在線聊天案例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
mybatis中<if>標(biāo)簽bool值類型為false判斷方法
這篇文章主要給大家介紹了關(guān)于mybatis中<if>標(biāo)簽bool值類型為false判斷方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用mybatis具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

