Friday, September 18, 2009

Debugging Unit Tests in Maven2 (mvn)

Recently I got fouled up by this issue in Intellij's IDEA. Basically IDEA loads up the Spring context one way, maven another. IDEA's trying to be helpful by doing this, but it's causing me headache. Instead of running and debugging my unit tests in IDEA, I had to resort to launching mvn on the command line and attaching a remote debugger to it via IDEA. How do you do this? Comme ca:

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=62905 -Xnoagent -Djava.compiler=NONE" -Dtest=YourTestClass test


Then create a remote debugging session in IDEA for port 62905.

It's pretty tedious because you have to fire up mvn, then wait for it to wait, and then start the debugging session from IDEA.

While you're at it, you might want to set -Dhibernate.show_sql=true and change your log4j.properties to include log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER to see what Hibernate is sending to the database.

No comments:

Post a Comment