5

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)?

3
  • in another source folder - src/int-test/java Commented Nov 6, 2012 at 19:56
  • 1
    I'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." Commented Nov 6, 2012 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. Commented Nov 6, 2012 at 22:02

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 ...<build><testSourceDirectory>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.