The test object is the service class of the Web project, and according to the information found on the Internet, execute the Times error as follows.
Use JUNIT4 for unit testing @runwith (Springjunit4classrunner.class)//Load configuration file, you can specify multiple profiles, locations specifies an array of @contextconfiguration (locations={"Classpath:spring/applicationcontext-*.xml", "Classpath: Spring/springmvc.xml "})//Start transaction control @transactional//configuration transaction manager, and specify automatic rollback @transactionconfiguration (transactionmanager=" TransactionManager ", defaultrollback=true) public class Basejunit4test { //test class inherits the class //Inject service object when testing ///Then use @test on the method, @RollBack, @Transaction and other annotations individually decorated}
After execution, the following error:
caused by Java.lang.IllegalStateException:WebApplicationObjectSupport Instance[resourcehttprequesthandler [ Locations=[class path resource [Assert/]],resolvers=[[email protected].] Does not run with a webapplicationcontext but In:org.springframework.context.support.GenericAppliactionContext ............
A similar problem has been found on the web, saying that it is possible to remove the static resource directory associated with the assert in the configuration file. It doesn't feel good, because it's no problem to start the project in Tomcat.
Just started with JUnit, not quite familiar, and later thought that the JUnit configuration might not support Web engineering. Then we searched how to unit test the controller layer, and found the @webappconfiguration annotation above the test class. Conjecture is precisely because of the lack of this annotation problem.
So in the test code added this annotation, will not error.
JUnit is very powerful, still need to study well.
Have a problem with this mark. This is my wrong set of questions.
JUnit Test error problem for Spring Web project