1
我已经在IntelliJ中创建了新的弹簧引导项目,并且我希望使用来自简单单元测试的弹簧引导上下文分开测试,所以我添加了maven failsafe插件。我的配置是这样的:IllegalStateException在通过maven failsafe插件运行spring引导测试时。
<!--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>
我在的IntelliJ测试类改名全自动生成的匹配模式和测试看起来是这样的:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ErpegApplicationTestIT {
@Test
public void contextLoads() {
}
}
的问题是,当我在InttelliJ运行这个测试,一切正常。但我跑得mvn verify
后我有:
[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
是否与类命名的问题吗?我应该采取不同的方法来区分这些测试吗?
无论如何感谢您的帮助。
首先你的配置[Maven的万无一失,插件(http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo。 html#includes)和[maven-failsafe-plugin](http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#includes)是不需要的,因为这些是默认值(约定超过配置)。你是否按照错误信息中的建议? – khmarbaise