As pappu_kity says, removing the empty catch block exposes the fact that your controller
field is null - and so probably hasn't been autowired.
To ensure that the field is autowired using @Autowired
you need to run the test with the SpringJUnit4ClassRunner
by annotating the AddSchoolTest
class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/path/to/applicationContext.xml" })
public class AddSchoolTest {
@Autowired
private UserManagementController controller;
@Test
public void testAddSchool() throws Exception {
ModelMap model = new ModelMap();
HttpServletRequest request = new MockHttpServletRequest();
Pricing pricing = new Pricing();
String userName = "Laily";
pricing.setName(userName);
//ModelAndView mav= controller.handleRequest();
ModelAndView mav= controller.addschool(pricing, model,null, request);
//fail("Not yet implemented");
assertNull(pricing);
assertFalse(model.isEmpty());
Assert.assertEquals("addschool", mav.getViewName());
}
}
Ensure that the @ContextConfiguration
is set appropriately for the locations of your Spring config files.