Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ integration test folder alongside main and test

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.

like image 924
Alkis Kalogeris Avatar asked Jan 24 '16 12:01

Alkis Kalogeris


People also ask

Where can I run an integration test?

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.


2 Answers

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.

like image 148
dunni Avatar answered Oct 13 '22 09:10

dunni


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

like image 43
tddmonkey Avatar answered Oct 13 '22 09:10

tddmonkey