I have a project containing pom.xml
and some JUnit
tests. Both pom.xml
and unit tests are corrects. But problem is that tests are not in src/test/java folder (I cannot use this folder). Is it possible to tell maven to execute tests from another source folder (which is also in this project)?
Asked
Active
Viewed 3,405 times
4
-
in another source folder - src/int-test/java – Nov 06 '12 at 19:56
-
1I'm sure you have great reasons why you can't use src/test/java. So I'm only going to ask "why?" because nobody has answered your question so far. (Maybe the answer will provide more insight.) One of the first things I learned about Maven was that you really should adapt to its conventions because it's just painful if you don't. That's the whole idea of "configuration vs. convention." – Marvo Nov 06 '12 at 20:16
-
Are these tests really unit tests? Based on the name of the folder i assume these tests are integration tests. If this is true you shouldn't use maven-surefire-plugin for such purposes. Better is to use maven-failsafe-plugin for such integration-tests. – khmarbaise Nov 06 '12 at 22:02
1 Answers
7
It is enough to add this part to your pom:
<project>
...
<build>
<testSourceDirectory>src/int-test/java</testSourceDirectory>
</build>
...
</project>
The test sources will be compiled during the test-compile
phase and the maven-surefire-plugin
will find the test classes too.

maba
- 47,113
- 10
- 108
- 118
-
Under maven 3.6.2 this results in the following error: `[ERROR] Some problems were encountered while processing the POMs: Malformed POM ....../pom.xml: Unrecognised tag: 'testSourceDirectory' (position: START_TAG seen ...
– Nat Ritmeyer Oct 27 '19 at 19:32`.