Tomasz Bawor
Tomasz Bawor

Reputation: 1657

IllegalStateException while running spring boot tests via maven failsafe plugin.

I have created new spring boot project in IntelliJ and I have wanted to separate tests using spring boot context from simple unit tests, so I have added maven failsafe plugin. My configuration looks like this:

        <!--RUNNING UNIT TESTS-->
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <excludes>
                    <exclude>**/*IT.java</exclude>
                </excludes>
            </configuration>
        </plugin>

        <!--RUNNING INTEGRATION TESTS-->
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

I have renamed automaticly generated in intellij test class to match pattern and test looks like this:

@RunWith(SpringRunner.class)
@SpringBootTest
public class ErpegApplicationTestIT {

    @Test
    public void contextLoads() {
    }

}

The problem is that while I run this test on InttelliJ, everything is working all right. But after I run mvn verify I have got:

[ERROR] initializationError(com.tbawor.ErpegApplicationTestIT)  Time elapsed: 0.005 s  <<< ERROR!
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @S
pringBootTest(classes=...) with your test

Is there a problem with class naming? Should I take diffrent aproach to separate those tests?

Thanks for your help anyway.

Upvotes: 1

Views: 1804

Answers (1)

Tomasz Bawor
Tomasz Bawor

Reputation: 1657

If anyone will come across that problem, I have found a solution. You just have to simply modify pom.xml:

          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-failsafe-plugin</artifactId>
             <version>2.20</version>
             <configuration>
                 <additionalClasspathElements>
                     <additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
                 </additionalClasspathElements>
             </configuration>
             <executions>
                 <execution>
                     <goals>
                         <goal>integration-test</goal>
                         <goal>verify</goal>
                     </goals>
                 </execution>
             </executions>
         </plugin>

Upvotes: 2

Related Questions