I am not familiar with JUnit . I was reading a Spring tutorial where I found they used JUnit in the tutorial . So i need little Junit help to pass over that section and get going on the spring tutorial.
tutorial :
http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html#step1.9 see section : 1.9. Write a test for the Controller
.Q1) I am surprised to see that they did not deploy the HelloController in the server but tested the view using JUnit ! ...thats interesting......but suppose instead of HelloController , if we had a HttpServlet ..can we still be able to test without deploying the Httpservlet in the server ?? I am asking because Httpservlet lives inside the server ....So can we test a Httpservlet without deploying it in the server using JUnit ?
Q2)
ModelAndView modelAndView = controller.handleRequest(n
ull, null);
why null,null ?
Q3)
assertEquals("hello.jsp", modelAndView.getViewName()
);
modelAndView.getViewName()
);
// how this can work upon ? controller is not yet deployed ..it cant respond....can it ??
Q4)
See the run output ...need to uderstand this
tests:
[junit] Running springapp.web.HelloWorldCo
ntrollerTe
sts
[junit] Oct 30, 2007 11:31:43 PM springapp.web.HelloControl
ler handleRequest
[junit] INFO: Returning hello view
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.03 sec
[junit] Testsuite: springapp.web.HelloWorldCo
ntrollerTe
sts
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.03 sec // WHY TWICE PRINT ??
[junit] ------------- Standard Error -----------------
[junit] Oct 30, 2007 11:31:43 PM springapp.web.HelloControl
ler handleRequest
[junit] INFO: Returning hello view // THIS IS NOT ERROR .WHY THIS IS UNDER StandardError?
[junit] ------------- ---------------- ---------------
Can you explain this run output ? I see there is some output under Standard Error ...but that is not error ......and also "Tests run: 1" has been printed twice ....why ? does JUnit execute twice the test case to print two times ?
Q5) what it checks
assertNotNull(modelAndView
.getModel(
));
looks like a null object checking ...if it finds null ..does that going to throw some error under Standard Error ??