Question: 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?

Answer: 
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](http://www.junit.org/), because it is best supported by Spring (see Spring Referece: [chapter 9 Testing](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#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](http://maven.apache.org/plugins/maven-surefire-plugin/) plugin.

```
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.8.1</version>
  <scope>test</scope>
</dependency>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.10</version>
  </plugin>

```

May you want to do some mocking than have a look at [easyMock](http://easymock.org/) or [Jmock](http://www.jmock.org/) or [Mockito](http://code.google.com/p/mockito/).

If you need to do integration tests, that access your application through its fronted than have a look at: [Selenium2/Webdriver](http://seleniumhq.org/docs/03_webdriver.html) - Therefore you need to start the server first, for example [Maven-Cargo](http://cargo.codehaus.org/Maven2+plugin) 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.
You will need a testing framework (like JUnit) and a framework for mocking Spring controllers. [EasyMock](http://easymock.org/) is a good choice. You can find some tutorials [here](http://blog.codehangover.com/getting-friendly-with-spring-junit-and-easymock/) and [here](http://www.abcseo.com/tech/java/testing-spring-controllers-with-easymock).