Spring+Junit4进行接口测试
2016-12-28 17:24
417 查看
1.配置pom.xml
[java] viewplain copy
print?
<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配置文件配置:[html] view
plain copy
print?
<bean id="testInterface" class="com.xxx.TestInterfaceImpl">
</bean>
自动扫描
接口实现类中配置[java] view
plain copy
print?
@Component
public class TestInterfaceImpl implements TestInterface {
spring配置文件配置
[html] view
plain copy
print?
<context:annotation-config/>
<context:component-scan base-package="com.xxx.servlet">
</context:component-scan>
3.编写接口测试代码
[java] viewplain copy
print?
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进行接口测试
- Spring+Junit4进行接口测试
- Spring+Junit4进行接口测试
- Spring+Junit4进行接口测试
- Spring+Junit4进行接口测试
- RxJava2.0在安卓中的二级缓存策略
- RabbitMQ四种Exchange类型之Direct (Java)
- Webcollector + Spring + MVC 搭建应用初探(二)
- 【leetcode】Add Binary-----Java
- java.lang.ExceptionInInitializerError解决办法
- Java写出杨辉三角
- Struts2接受参数几种方式
- Java中对象的访问方式
- spring-boot-swagger2 使用手册
- Spring Security(08)——intercept-url配置
- spring boot 国际化
- java文件读写实例
- 支付宝(移动支付)服务端java版
- Spring Security授权 AccessDecisionManager