Разница между тестовыми и проверочными задачами в 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 при выполнении ./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. Это правильно?


person andrewgazelka    schedule 30.04.2018    source источник


Ответы (1)


Задача Gradle check зависит от задачи test, что означает, что test выполняется до запуска check. В документации говорится, что проверка выполняет все задачи проверки в проекте, включая test, а также Плагины задач добавляют в проект:

введите описание изображения здесь

Если вы, например, добавляете плагин checkstyle в свой проект, вы можете запускать его задачи checkstyleMain и checkstyleTest по отдельности или выполнить полную проверку проекта с помощью check. В этом случае будут выполняться задачи test, checkstyleMain и checkstyleTest.
Тогда как test всегда просто выполняет ваши модульные тесты.

person UnlikePluto    schedule 30.04.2018
comment
Можно добавить, что test - это задача, которая действительно что-то делает, а check - это так называемая задача жизненного цикла, которая объединяет только другие задачи. Самая распространенная задача жизненного цикла - build. - person Lukas Körfer; 01.05.2018