测试和检查之间的差异

and*_*lka 35 gradle gradlew build.gradle

我的build.gradle情况如下:

group 'groupName'
version 'version'

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8

repositories {
    . . .
}

dependencies {
    . . .
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
Run Code Online (Sandbox Code Playgroud)

./gradlew tasks我收到的时候

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Run Code Online (Sandbox Code Playgroud)

这两项任务有什么区别?输出与... ./gradlew check相同./gradlew test.

andrewgazelka $ ./gradlew check

> Task :compileJava
warning: Element `SHIFT_UP_THRESHOLD` is set to `UNDEFINED`. This may be ok for this variable.
warning: Element `SHIFT_DOWN_THRESHOLD` is set to `UNDEFINED`. This may be ok for this variable.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 warnings

> Task :test FAILED

MathTest > testX FAILED
    java.lang.AssertionError at MathTest.java:40

MathTest > testY FAILED
    java.lang.AssertionError at MathTest.java:55

SimulatorTest > testZ FAILED
    java.lang.IllegalArgumentException at SimulatorTest.java:71

30 tests completed, 3 failed


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/andrewgazelka/IdeaProjects/RobotCode2018/build/reports/tests/test/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
3 actionable tasks: 3 executed
andrewgazelka $ ./gradlew test

> Task :test FAILED

MathTest > testX FAILED
    java.lang.AssertionError at MathTest.java:40

MathTest > testY FAILED
    java.lang.AssertionError at MathTest.java:55

SimulatorTest > testZ FAILED
    java.lang.IllegalArgumentException at SimulatorTest.java:71

30 tests completed, 3 failed


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/andrewgazelka/IdeaProjects/RobotCode2018/build/reports/tests/test/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
3 actionable tasks: 1 executed, 2 up-to-date
Run Code Online (Sandbox Code Playgroud)

据我所知,./gradle test./gradle check.它是否正确?

Unl*_*uto 50

Gradle check任务取决于test任务,这意味着在运行检查之前执行测试.该文件是检查统计执行项目中的所有验证工作,包括测试和任务也插件添加到项目:

在此输入图像描述

例如,如果您将checkstyle插件添加到项目中,则可以单独运行其任务checkstyleMain,也可以使用checkstyleTest执行完整的项目验证check.在这种情况下,任务test,checkstyleMain并将checkstyleTest运行.
test总是只执行您的单元测试.

  • 有人可能会补充说`test`是一个实际做某事的任务,而`check`是一个所谓的生命周期任务,只捆绑其他任务.最常见的生命周期任务是`build`. (9认同)