Maven and JUnit tests debug with Eclipse

We are going to show you how to connect to JUnit tests while it is being executed during maven build. We are going to use Eclipse debugger and Eclipse Maven plugin which we were installing here at Maven 3 Eclipse plugin setup post.

When you have Maven3 Plugin Eclipse configured perform these steps to debug JUnit maven test:

1.Click Debug Configurations... option in the Debug menu

Eclipse ‘Debug Configurations’ option

2. Add a new Maven Build configuration

3. Enter following data:

Name – Name of the buildBase directory – A project that is going to be buildGoals – -DforkMode=never test

Maven is running tests in a separate process by default. By setting forkMode option to never you tell maven not to fork the test process. This way, while connected to the build process you are able to debug it.

Eclipse ‘Debug Configurations’ option screen

4. Click Debug button

That’s it. If you have any breakpoints set in your project junit tests code, program execution will stop on them.