欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring+Junit4進(jìn)行接口測(cè)試實(shí)例代碼

 更新時(shí)間:2018年01月31日 09:26:56   作者:Wind_365  
這篇文章主要介紹了Spring+Junit4進(jìn)行接口測(cè)試實(shí)例代碼,涉及pom.xml、bean的配置,以及接口測(cè)試代碼等相關(guān)內(nèi)容,小編覺得還是挺不錯(cuò)的,這里分享給大家,需要的朋友可以參考下

本文研究的主要是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í)例代碼的全部內(nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

相關(guān)文章

最新評(píng)論