JUnit Test error problem for Spring Web project

Source: Internet
Author: User
Tags assert

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.