I just threw together a quick Spring MVC app as a demo to replace an internal app in my department.
Now I’m supposed to demonstrate how Test Driven Development works in relation to Spring MVC.
Unfortunately I didn’t use TDD to build the demo and I’m not sure where to get started with it.
I’m using Maven for the build – are there any Maven-based testing frameworks that are easy to get started with in Spring MVC and that have good tutorials?
Where do I start?
Because TDD has an huge influence how the code and methods are written, it is in most complex situations impossible to fake it!
I mean if you do TDD then the code will be written in a kind that is is easy to test. If you don’t do TDD the code will be hopefully testable too, but in a complete different way. — So if you have some experience in TDD you will see the difference in the code.
So if there is not to much code and this TDD thing is a really serious requirement, then throw the code a way and do it again.
Anyway if you do it again or not the tools you need will be the same:
You will need a test framwork: Go with Junit 4, because it is best supported by Spring (see Spring Referece: chapter 9 Testing).
The integration in Maven is very easy:
Put the test cases under `src/test/java’ and then (but this dependens on your style) in a parallel package structure to the classes under test. All you need is the maven-sure-fire plugin.
May you want to do some mocking than have a look at easyMock or Jmock or Mockito.
If you need to do integration tests, that access your application through its fronted than have a look at: Selenium2/Webdriver – Therefore you need to start the server first, for example Maven-Cargo will help you. But a warning: to get your first web base integration test running, that starts the server automatically and deploy the application automatically is a hard task, and will may take you more than one day.