小编典典

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

spring-boot

我正在迁移现有项目以进行引导。我使用start.spring.io创建了一个全新的项目,并复制了源代码,等等。所有内容都可以编译,但是当我执行“
mvn测试”时,它会编译类,但仅执行默认的“ 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是否设置了我不符合的surefire配置?

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


阅读 645

收藏
2020-05-30

共1个答案

小编典典

Spring
Boot将Surefire插件配置为运行名称以TestTests而不以开头的所有测试类Abstract。您可以spring-boot- starter-parentpom中看到此配置。如果您的测试类已命名,TestAuthController则它与该配置不匹配。将其重命名为AuthControllerTestAuthControllerTests应解决您的问题。

2020-05-30