views:

243

answers:

2

We are using filtered testResources in JUnit-tests that are usually executed by the maven surefire plugin. That is, the pom contains a section

  <build>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>
    ...

How can I run such JUnit-tests in the debugger? If I execute the tests in eclipse the tests fail since the test resources are not filtered. If the filtered test resources would be written somewhere into the target directory, I could just use this as an additional source path - but this is not the case. If I try to run the maven build in eclipse with Debug As / maven test , the build does not stop in the breakpoints. Any other ideas?

+1  A: 

There are several options. First you can run the test from the command line specifying maven.surefire.debug. Per default surefire tests are run in a forked JVM which means that if you just debug the maven process you won't get any stops in the test breakpoints. That's probably what you are seeing now. See also http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

Othwerwise I would recommend to configure your project within the IDE as a maven project. If the project is configured as maven project the resource filtering will occur automatically prior to running the tests. That's at least how it works within Idea and I think Eclipse does the same with the right maven plugin installed.

You can also run the maven build once from the command line and then manually add the target/test-classes directory to your IDE configuration. Works, but is a little bit dodgy.

Hardy
+1  A: 

If I execute the tests in eclipse the tests fail since the test resources are not filtered.

Use m2eclipse and resources will get filtered inside Eclipse.

Pascal Thivent