0

I have two test directories in my java project. One contains integration tests and another unit tests:

── src
│   ├── it
│   │   └── java
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│       └── java

I'm using the failsafe plugin to run these integration tests. To register the src/it/java directory as a testing source I'm using the build-helper-maven-plugin plugin. See https://stackoverflow.com/a/17866387/11550924 for the full setup.

It works fine from the command line - running mvn verify successfully executes my integration tests.

However in Eclipse I get import warnings on all classes that are scoped as test (e.g. junit) in the integration test classes.

It must be that Eclipse isn't recognising this folder as one which contains tests.

Does anyone know how to tell Eclipse that this folder is a testing folder?

jd96
  • 535
  • 3
  • 12
  • Alternatively, you could use the failsafe plugin - eg, as described here : https://www.baeldung.com/maven-integration-test – racraman Nov 01 '20 at 08:07
  • @racraman I am using the failsafe plugin. The link to the setup shows what's in my pom.xml. I'll clarify in the question. – jd96 Nov 01 '20 at 08:09
  • Great - but then all tests can live under src/test , and it’s the naming of the tests that differentiate unit tests from integration tests. You could always have the integration tests under a new src/test/it . – racraman Nov 01 '20 at 08:20
  • I could, sure. But this is all working from the command line. I just want to know how to make it work in Eclipse. – jd96 Nov 01 '20 at 10:14
  • I think Eclipse maven plugin is only recognizing files under `src/test` as tests. Is there any specific reason for creating `it/java` parallel to `test/java` ? Any reasons or constraints for not keeping all tests together under same hierarchy. Something like `src/test/java/it` & `src/test/java/ut`. We can also use Tags & Profiles to decide which are executed by default in maven build. – Arkantos Nov 01 '20 at 10:55
  • @Arkantos it's just a habit I have from a previous Scala project. We were using a different IDE though so maybe that's why the issue didn't arise. I like the separation of integration and unit tests into different directories. I suppose I could just put try in the hierarchy you've suggested. – jd96 Nov 01 '20 at 11:26

1 Answers1

0

I switched to IntelliJ and this folder structure worked fine.

If you can't do that just put the integration tests under src/test/java/it.

jd96
  • 535
  • 3
  • 12