栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring+Junit4进行接口测试实例代码

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring+Junit4进行接口测试实例代码

本文研究的主要是Spring+Junit4进行接口测试的一个相关实例,具体实现代码如下。

1.配置pom.xml
 
  org.springframework 
  spring-context 
  4.3.2.RELEASE 
 
 
 
  org.springframework 
  spring-test 
  4.3.2.RELEASE 
 
 
 
  junit 
  junit 
  4.12 
 
2.配置bean

testInterface可以进行手动配置或自动扫描

手动配置

spring配置文件配置:

 
   

自动扫描

接口实现类中配置

@Component 
public class TestInterfaceImpl implements TestInterface { 

spring配置文件配置

 
 
 
   
   
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); 
  } 
总结

以上就是本文关于Spring+Junit4进行接口测试实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/141839.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号