This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.
No announcement yet.
JUnit testing Spring Controllers and ValidatorsPage Title Module
Are there any built in classes/standard methodology for using JUnit to test Spring Controllers (e.g. SimpleFormController) and validator classes? Some help, or even a pointer in the right director would help a lot.
Any of the test superclasses in org.springframework.test can be used. The controllers are just another class. Its just a matter of setting up your mock objects appropriately. The book Pro Spring covers testing topics, too - a good book to have.
Thanks for that, and I do actually already have that book.
What I'm having problems with now are with testing controllers with JUnit. How can I perform a post to my controller to test if it's doing the correct things?
I have a web page and a command object. The command object (RefCodeManager) has a property containing a list of Ref Codes. There are two buttons at the bottom of the page, 'Add' and 'Update'. 'Add' simply adds another blank 'ref code' to the list of ref codes in the command object and then reloads the page. 'Update' takes the command object and the ref codes in it and inserts/updates them to the database.
The problem comes when testing that the 'Add' and 'Update' submit buttons are doing their job. Here's what I have to test the add button. But even with out the request.addParameter("add", "") it still seems to work?!?