Debugging maven junit tests with filtered resources?

We use filtered test resources in JUnit tests, which are usually performed by the maven surefire plugin. That is, 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 run tests in eclipse, the tests fail because the test resources are not filtered. If the filtered test resources are written somewhere in the target directory, I would just use this as an additional path to the source, but it is not. If I try to run the maven build in eclipse using the Debug As / maven test, the build does not stop at breakpoints. Any other ideas?

+4
source share
2 answers

There are several options. First, you can run the test from the command line with maven.surefire.debug. By default, authentication tests run in a forked JVM, which means that if you just debug the maven process, you will not get any stops at the test checkpoints. This is probably what you are seeing right now. See also http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

In any case, I would recommend setting up your project in the IDE as a maven project. If the project is configured as a maven project, resource filtering will occur automatically before the tests run. At least how it works in Idea, and I think Eclipse does the same with the maven plugin installed.

You can also start the maven build from the command line and then manually add the target / test class directory to your IDE configuration. It works, but a little quirky.

+4
source

If I run tests in eclipse, the tests fail because the test resources are not filtered.

Use m2eclipse and resources will be filtered out inside Eclipse.

+1
source

Source: https://habr.com/ru/post/1310091/


All Articles