---=== C O D E A B B E Y ===--- my site with programming problems (and Certificates)
Rodion Gork wrote:I'm sorry but it is not clear what exactly do you mean. Unit-Testing of server-side classes is nothing different from testing anything else - as you want to test only class itself. For example if you mean to test some MyServlet#doGet method, you instantiate the object, then call doGet passing to it some mocks of "request" and "response" parameters. You set necessary values on "request" and then check that proper data were set on "response".
If your servlet performs whimsical printing to response.outputStream and you feel trouble with testing this, you should come to conclusion that your doGet method has poor architecture. I.e. if you are serving some data to output (e.g. JSON), you should instead prepare this json in separate method, cover it with separate unit-test and then only call this method in your doGet. Unit-test for doGet then should only check that whatever is served by such method, is printed correctly.
If you print the whole JSP-generated response in the servlet - then you should feel that it is not correct to test it with unit-test. You should prefer switching to proper MVC architecture and while covering M and C with unit-tests, Views could be tested with things like Selenium, if necessary.
The same with anything other. E.g. with Spring you will have Controllers which should be tested in similar manner. But if your tests become complicated then you should understand that something in the controller should be moved level down, e.g. to Service layer etc. You mock services or daos for controllers. You mock daos for services. And if you want to test daos itself, you either mock lower persistence level, or use things like DbUnit...
Something like this... Feel free to elaborate your question
How I will deploy it for testing, how it will get message, can we test them in eclipse itself (means in development mode) with some mock server kind of queries.
Hope you got my question.
---=== C O D E A B B E Y ===--- my site with programming problems (and Certificates)
Rodion Gork wrote:
Yes I got it, but I should tell this is not unit-testing