“Spring Boot集成测试无法找到配置”

huangapple go评论64阅读模式
英文:

Spring Boot integration test can't find configuration

问题

我有一个简单的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: 无法找到 @SpringBootConfiguration,请使用 @ContextConfiguration 或者 @SpringBootTest(classes=...) 与您的测试一起使用

我正在使用以下版本:

  • Java: 14
  • Maven: 3.6.0
  • spring-boot: 2.3.4.RELEASE
  • junit-jupiter: 5.6.2(我没有使用 JUnit 4)
  • maven-failsafe-plugin: 3.0.0.M5

对于为什么在命令行上失败,您有任何想法吗?

英文:

I have a simple Spring Boot application, consisting only of this class:

@SpringBootApplication
public class TestApplication {

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

I want to test whether the application starts. That test looks like this:

@SpringBootTest
public class UserServiceIT {

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

}

When I run this test from my IDE (IntelliJ), it passes. This is the expected behavior.

When I run it from the command line (mvn integration-test), I get the following failure:

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

I'm using the following versions:

  • Java: 14
  • Maven: 3.6.0
  • spring-boot: 2.3.4.RELEASE
  • junit-jupiter: 5.6.2 (I'm not using JUnit 4)
  • maven-failsafe-plugin: 3.0.0.M5

Any ideas as to why this fails on the command line?

答案1

得分: 1

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

英文:

I tried rolling back the version of maven-failsafe-plugin to 3.0.0.M4 and the test passed from the command line. Therefore this appears to be a bug in 3.0.0.M5.

huangapple
  • 本文由 发表于 2020年10月9日 08:08:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64272249.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定