Spring Boot-我的单元测试被跳过 [英] Spring Boot - My unit tests are being skipped

查看:814
本文介绍了Spring Boot-我的单元测试被跳过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移现有项目以进行引导.我使用start.spring.io创建了一个全新的项目,并将其复制到源代码等上.所有内容均可编译,但是当我执行"mvn测试"时,它将编译类,但仅执行默认的"ApplicationTests"(由start创建) .spring.io).

I am migrating an existing project to boot. I created a brand new project using start.spring.io and copied over the source code, etc. Everything compiles, but when I do a 'mvn test' it compiles the classes but then only executes the default 'ApplicationTests' (created by start.spring.io).

以下是Maven输出的摘录:

Here's an excerpt from the maven output:

    [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',那么它将运行该特定的单元测试:

What's even stranger is that if I pass '-Dtest=TestAuthController' then it does run that specific unit test:

    [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配置?

What am I doing wrong? Does spring boot setup a surefire config that I'm not conforming to?

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

Any help would be greatly appreciated! -Trey

推荐答案

Spring Boot将Surefire插件配置为运行名称以TestTests结尾但不以Abstract开头的所有测试类.您可以看到

Spring Boot configures the Surefire plugin to run all test classes that have a name ending with Test or Tests but not starting with Abstract. You can see this configuration in the spring-boot-starter-parent pom. If your test class is named TestAuthController then it doesn't match this configuration. Renaming it to AuthControllerTest or AuthControllerTests should fix your problem.

这篇关于Spring Boot-我的单元测试被跳过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆