Hello, just starting to learn spring, maven, hibernate. Trying to write a simple crud application. I launch, jumps out the error java.lang.AssertionError: No ModelAndView found. Could you tell me what could be the problem? Test class:

@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration("file:src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml") public class AppTests { private MockMvc mockMvc; @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired protected WebApplicationContext wac; @Before public void setup() { this.mockMvc = webAppContextSetup(this.wac).build(); } @Test public void simple() throws Exception { mockMvc.perform(get("/")) .andExpect(status().isOk()) .andExpect(view().name("hello")); } } 

Controller:

 @Controller public class UserController { private UserService userService; @Autowired(required = true) @Qualifier(value = "userService") public void setUserService(UserService userService) { this.userService = userService; } @RequestMapping(value = "/users", method = RequestMethod.GET) public String listUsers(Model model){ model.addAttribute("user", new User()); model.addAttribute("listUsers", this.userService.getListUsers()); return "users"; } @RequestMapping(value = "/users/add", method = RequestMethod.POST) public String addUser(@ModelAttribute("user") User user){ if(user.getId() == 0){ this.userService.addUser(user); }else { this.userService.updateUser(user); } return "redirect:/users"; } @RequestMapping("/remove/{id}") public String removeUser(@PathVariable("id") int id){ this.userService.removeUser(id); return "redirect:/users"; } @RequestMapping("edit/{id}") public String editUser(@PathVariable("id") int id, Model model){ model.addAttribute("user", this.userService.getUserById(id)); model.addAttribute("listUsers", this.userService.getListUsers()); return "users"; } @RequestMapping("/userdata/{id}") public String userData(@PathVariable("id") int id, Model model){ model.addAttribute("user", this.userService.getUserById(id)); return "userdata"; } } 

Stack trace:

 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project UserManger: There are test failures. Please refer to C:\Users\zosia\Desktop\JAVA\CRUD\PROJECT\target\surefire-reports for the individual test results. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) at org.codehaus.classworlds.Launcher.main(Launcher.java:47) Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures. Please refer to C:\Users\zosia\Desktop\JAVA\CRUD\PROJECT\target\surefire-reports for the individual test results. at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:91) at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:320) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:892) at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:755) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 20 more 
  • Full stack trace specify - GenCloud
  • @GenCloud Added full stack trace - Zosya 8:08 PM

1 answer 1

Browse the directory

 C:\Users\zosia\Desktop\JAVA\CRUD\PROJECT\target\surefire-reports 

to view the error of the test itself. This parameter is registered

 <build> <testSourceDirectory>src/test/java</testSourceDirectory> </build> 
  • Sorry, I'm just not very well versed in the subject yet) Error of the test itself in a text file or xml? Because in text only Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.502 sec <<< FAILURE! - in usermanager.AppTests simple (usermanager.AppTests) Time elapsed: 4.01 sec <<< FAILURE! java.lang.AssertionError: No ModelAndView found at usermanager.AppTests.simple (AppTests.java:35) - Zosya