The research in this article mainly involves a related example of Spring+Junit4 interface testing. The specific implementation code is as follows.
<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>
testInterface can be configured manually or automatically scanned
Manual configuration
Spring configuration file configuration:
<bean id="testInterface"> </bean>
Automatic scanning
Configuration in interface implementation class
@Component public class TestInterfaceImpl implements TestInterface {Spring configuration file configuration
<context:annotation-config/> <context:component-scan base-package="com.xxx.servlet"> </context:component-scan>
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); }The above is all the content of this article about the code for the interface test example of Spring+Junit4, and I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!