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.
The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With