Spring 启动集成测试找不到配置



我有一个简单的Spring Boot应用程序,仅由以下类组成:

@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}

我想测试应用程序是否启动。这个测试看起来是这样的:

@SpringBootTest
public class UserServiceIT {
@Test
public void testContextLoads() {
assertTrue(true);
}
}

当我从IDE(IntelliJ(运行此测试时,它通过了。这是预期的行为。

当我从命令行(mvn integration-test(运行它时,我得到以下失败:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

我使用以下版本:

  • Java:14
  • Maven:3.6.0
  • 弹簧套:2.3.4.释放
  • junit jupiter:5.6.2(我没有使用junit 4(
  • maven故障保护插件:3.0.0.M5

关于为什么在命令行中失败,有什么想法吗?

我尝试将maven-failsafe-plugin的版本回滚到3.0.0.M4,并从命令行通过测试。因此,这似乎是3.0.0.M5中的一个错误。

最新更新