One. Application scenario: Common Java Web Integration Spring test,
Project structure: Using the method of adding jars, not the way Maven joins dependencies
Note: If this is the way to introduce a jar package, for example: Spring-test4.0.5.jar and Junit4.12.jar,
If you are using the Junit4.12.jar version, to add the Hamcrest-core1.3.jar package, the following error is reported:
Java.lang.Exception:No tests found matching [{Exactmatcher:fdisplayname=test], {exactmatcher:fdisplayname=test ( Org.devin.hellochat.test.Test)], {leadingidentifiermatcher:fclassname=org.devin.hellochat.test.test, Fleadingidentifier=test]] from [email protected] at Org.junit.internal.requests.FilterRequest.getRunner ( FILTERREQUEST.JAVA:40) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest ( junit4testloader.java:77) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest ( junit4testloader.java:68) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests ( junit4testloader.java:43) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests ( remotetestrunner.java:444) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests ( remotetestrunner.java:675) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (Remotetestrunner.java : 382) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.maIn (remotetestrunner.java:192)
Two. Use:
1.applicationcontext.xml spring-mvc.xml configuration file is placed under resource source file, Note: the Web. xml file needs to be configured <context-param></ Context-param>, and introduced the Applicationcontext.xml file,
Initialization of Spring-mvc.xml file in Sevlet configuration required
@RunWith (Springjunit4classrunner.class)
@ContextConfiguration ({"Classpath:applicationContext.xml", "Classpath:spring_mvc.xml"})
public class test{
@Automired
Private Itemcatservice Itemcatservice;
@Test
public void Test () {
System.out.println (Itemcatservice)
}
}
The 2.applicationcontext.xml spring-mvc.xml configuration file is placed in the Web-inf directory:
@RunWith (Springjunit4classrunner.class)
@ContextConfiguration ({"File:webcontent/web-inf/applicationcontext.xml", "File:webcontent/web-inf/spring_ Mvc.xml "})
public class test{
@Automired
Private Itemcatservice Itemcatservice;
@Test
public void Test () {
System.out.println (Itemcatservice)
}
}
Spring and JUNIT4 Integration test