Reputation: 17755
I want to add some integration tests to a spring boot application. The resulting structure would be this
MyProject
├── myapp.iml
├── pom.xml
└── src
├── integration-test (integration test sources root)
│ ├── java
│ │ └── com
│ │ └── mysite
│ │ └── myapp
│ │ └── AppTestIT.java
│ └── integration-test.iml
│
├── main (sources root)
│ ├── java
│ │ └── com
│ │ └── mysite
│ │ └── myapp
│ │ └── App.java
│ └── main.iml
│
└── test (test sources root)
├── java
│ └── com
│ └── mysite
│ └── myapp
│ └── AppTest.java
└── test.iml
Is this possible? I'm doing this in Intellij 15 Ultimate
and it doesn't recognise the package as com.mysite.myapp
in my integration tests. Instead it recognises this java.com.mysite.myapp
. It doesn't follow the convention as it does with main
and test
, which is expected. Is there a way to add more folders alongside main
and test
and follow the same conventions (java folder not taken into consideration for the package declaration)?
If not, what is the best practice regarding the project structure when including integration tests? Should they be in the test folder? I would like to avoid that if possible.
Upvotes: 9
Views: 12778
Reputation: 44545
The correct way in this case would be to change the Maven configuration appropriately, so that it also works when executing the build on command line (e.g. on a build server etc.). You can do this by configuring the build-helper-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
IntelliJ picks up this configuration and marks the folder automatically as test source folder.
Upvotes: 23
Reputation: 21184
This should be as easy as right clicking the integration-test
folder, scrolling down to "Mark Directory As..." and selecting "Test Sources Root".
Note that if you have other developers working on this project they will have to do the same thing (unless you share IDEA files).
Upvotes: 17