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

Eclipse ‘Debug Configurations’ option

2. Add a new Maven Build configuration

3. Enter following data:

Name – Name of the build
Base directory – A project that is going to be build
Goals-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

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.

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>