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

这篇文章主要介绍了Spring+Junit4进行接口测试实例代码,涉及pom.xml、bean的配置,以及接口测试代码等相关内容,小编觉得还是挺不错的,这里分享给大家,需要的朋友可以参考下

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

1.配置pom.xml

  org.springframeworkspring-context4.3.2.RELEASE org.springframeworkspring-test4.3.2.RELEASE junitjunit4.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进行接口测试实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

以上就是Spring+Junit4进行接口测试实例代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java