Spring Boot - 我的单元测试被跳过

2024-04-20

我正在迁移现有项目以启动。我使用 start.spring.io 创建了一个全新的项目,并复制了源代码等。一切都会编译,但是当我执行“mvn test”时,它会编译类,但只执行默认的“ApplicationTests”(由 start 创建) .spring.io)。

以下是 Maven 输出的摘录:

    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pendview ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\dev\pendview2\src\test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pendview ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 26 source files to C:\dev\pendview2\target\test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ pendview ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

更奇怪的是,如果我通过 '-Dtest=TestAuthController' 那么它确实会运行特定的单元测试:

    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pendview ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 26 source files to C:\dev\pendview2\target\test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ pendview ---
    [INFO] Surefire report directory: C:\dev\pendview2\target\surefire-reports

    (skipped output of AuthControllerTest for brevity)

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------Results :

    Tests run: 6, Failures: 0, Errors: 0, Skipped: 0

我究竟做错了什么? Spring Boot是否设置了我不符合的万无一失的配置?

任何帮助将不胜感激! -特雷


Spring Boot 配置 Surefire 插件来运行所有名称以以下结尾的测试类Test or Tests但不是从Abstract。你可以看到这个配置在spring-boot-starter-parent pom https://github.com/spring-projects/spring-boot/blob/v1.1.6.RELEASE/spring-boot-starters/spring-boot-starter-parent/pom.xml#L86-L92。如果你的测试类被命名为TestAuthController那么它与这个配置不匹配。将其重命名为AuthControllerTest or AuthControllerTests应该可以解决你的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Boot - 我的单元测试被跳过 的相关文章

随机推荐