Home > Back-end >  Spring Mvc junit mock test has been an error 404
Spring Mvc junit mock test has been an error 404

Time:10-06

Package the controller;

The import org. Junit. Before;
The import org. Junit. Test;
The import org. Junit. Runner. RunWith;
The import org. Springframework. Beans. Factory. The annotation. Autowired;
The import org. Springframework. Test. The context. ContextConfiguration;
The import org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner;
The import org. Springframework. Test. The context. Web. WebAppConfiguration;
The import org. Springframework. Test. Web. Servlet. MockMvc;
The import org. Springframework. Test. Web. Servlet. Request. MockMvcRequestBuilders;
The import org. Springframework. Test. Web. Servlet. Result. MockMvcResultHandlers;
The import org. Springframework. Test. Web. Servlet. Result. MockMvcResultMatchers;
The import org. Springframework. Test. Web. Servlet. Setup. MockMvcBuilders;
The import org. Springframework. Web. Context. WebApplicationContext;

@ RunWith (SpringJUnit4ClassRunner. Class)
@ ContextConfiguration (locations={" classpath * : spring - mybatis. XML ",
"The classpath * : spring MVC - XML", "classpath * : generatorConfig. XML,"
"Classpath * : JDBC. The properties," "classpath * : log4j properties", "classpath * : mybatis - config. XML"})
@ WebAppConfiguration
Public class AuthControllerTest {

The @autowired
Private WebApplicationContext wac.

Private MockMvc MockMvc;

@ Before
Public void setUp () throws the Exception {
MockMvc=MockMvcBuilders. WebAppContextSetup (wac). The build ();
}

@ Test
Public void testTinchermage () throws the Exception {
MockMvc. Perform (MockMvcRequestBuilders. Get ("/auth/sysauthuser "))
AndDo (MockMvcResultHandlers. Print ())
AndExpect (MockMvcResultMatchers. The status (). IsOk ())
AndDo (MockMvcResultHandlers. Print ())
AndReturn ();
}

@ Test
Public void testTincher () {
}

@ Test
Public void testOrganizeTree () {
}

@ Test
Public void testList () {
}

}



Java. Lang. AssertionError: Status expected: & lt; 200 & gt; But the was: & lt; 404 & gt;
The at org. Springframework. Test. Util. AssertionErrors. Fail (60) AssertionErrors. Java:
The at org. Springframework. Test. Util. AssertionErrors. AssertEquals (AssertionErrors. Java: 89)
The at org. Springframework. Test. Web. Servlet. Result. StatusResultMatchers $10. Match (StatusResultMatchers. Java: 655)
The at org. Springframework. Test. Web. Servlet. MockMvc $1. AndExpect (MockMvc. Java: 171)
At the controller. AuthControllerTest. TestTinchermage (AuthControllerTest. Java: 38)
At sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
At sun. Reflect. NativeMethodAccessorImpl. Invoke (NativeMethodAccessorImpl. Java: 62)
At sun. Reflect. DelegatingMethodAccessorImpl. Invoke (43) DelegatingMethodAccessorImpl. Java:
The at Java. Lang. Reflect. Method. Invoke (498) Method. The Java:
The at org. Junit. Runners. Model. FrameworkMethod $1. RunReflectiveCall (FrameworkMethod. Java: 50)
The at org. Junit. Internal. Runners. Model. ReflectiveCallable. Run (ReflectiveCallable. Java: 12)
The at org. Junit. Runners. Model. FrameworkMethod. InvokeExplosively (FrameworkMethod. Java: 47)
The at org. Junit. Internal. Runners. Statements. InvokeMethod. Evaluate (InvokeMethod. Java: 17)
The at org. Junit. Internal. Runners. Statements. RunBefores. Evaluate (RunBefores. Java: 26)
The at org. Springframework. Test. The context. Takeup. Statements. RunBeforeTestMethodCallbacks. Evaluate (RunBeforeTestMethodCallbacks. Java: 75)
The at org. Springframework. Test. The context. Takeup. Statements. RunAfterTestMethodCallbacks. Evaluate (RunAfterTestMethodCallbacks. Java: 86)
The at org. Springframework. Test. The context. Takeup. Statements. SpringRepeat. Evaluate (SpringRepeat. Java: 84)
The at org. Junit. Runners. ParentRunner. RunLeaf (ParentRunner. Java: 325)
The at org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner. RunChild (SpringJUnit4ClassRunner. Java: 254)
The at org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner. RunChild (SpringJUnit4ClassRunner. Java: 89)
The at org. Junit. Runners. ParentRunner $3. The run (ParentRunner. Java: 290)
The at org. Junit. Runners. ParentRunner $1. The schedule (ParentRunner. Java: 71)
The at org. Junit. Runners. ParentRunner. RunChildren (ParentRunner. Java: 288)
The at org. Junit. Runners. ParentRunner. Access the $000 (ParentRunner. Java: 58)
At org. Junit. Runners. ParentRunner $2. The evaluate (ParentRunner. Java: 268)
The at org. Springframework. Test. The context. Takeup. Statements. RunBeforeTestClassCallbacks. Evaluate (RunBeforeTestClassCallbacks. Java: 61)
The at org. Springframework. Test. The context. Takeup. Statements. RunAfterTestClassCallbacks. Evaluate (RunAfterTestClassCallbacks. Java: 70)
The at org. Junit. Runners. ParentRunner. Run (ParentRunner. Java: 363)
The at org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner. Run (SpringJUnit4ClassRunner. Java: 193)
At org. Eclipse JDT. Internal. Takeup. Runner. JUnit4TestReference. Run (86) JUnit4TestReference. Java:
At org. Eclipse JDT. Internal. Junit. Runner. TestExecution. Run (TestExecution. Java: 38)
At org. Eclipse JDT. Internal. Junit. Runner. RemoteTestRunner. RunTests (RemoteTestRunner. Java: 538)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related