【问题标题】:Difference between test and check tasks in GradleGradle 中测试和检查任务的区别
【发布时间】:2018-10-10 19:03:24
【问题描述】:

我的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'
}

在 Gradle 中做 ./gradlew tasks 我收到

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

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

andrewgazelka $ ./gradlew check

> 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

据我了解,./gradle test./gradle check。这是正确的吗?

【问题讨论】:

    标签: gradle gradle-task


    【解决方案1】:

    Gradle check 任务依赖于test 任务,这意味着testcheck 运行之前执行。 documentation 声明 check 执行项目中的所有验证任务,包括 test 以及插件添加到项目中的任务:

    例如,如果您将checkstyle 插件添加到您的项目中,您可以单独运行其任务checkstyleMaincheckstyleTest,或者使用check 执行完整的项目验证。在这种情况下,将运行任务 testcheckstyleMaincheckstyleTest
    test 总是只执行你的单元测试。

    【讨论】:

    • 可以补充一点,test 是一个实际做某事的任务,而check 是所谓的生命周期任务,只是捆绑了其他任务。最常见的生命周期任务是build
    猜你喜欢
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2019-12-21
    • 1970-01-01
    • 2017-12-24
    相关资源
    最近更新 更多