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

在 Gradle,当我做 abc0的时候,我收到

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 something ./gradle check对吗?

35143 次浏览

Gradle check任务依赖于 test任务,这意味着在运行 check之前执行 test文件指出,check 执行项目中的所有验证任务,包括 test和任务插件添加到项目中:

enter image description here

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