Как написать тестовую задачу интеграции Java в Gradle с помощью JUnit5?

С Junit4 у меня было следующее определение интеграционного теста:

task testIntegration(type: Test, dependsOn: jar) {
    group 'Verification'
    description 'Runs the integration tests.'
    testLogging {
        showStandardStreams = true
    }

    testClassesDirs = sourceSets.testInt.output.classesDirs
    classpath = sourceSets.testInt.runtimeClasspath
    systemProperties['jar.path'] = jar.archivePath
}

Однако с JUnit5 это больше не работает. Я не могу понять, что изменить (слишком поздно). Любые подсказки?

Я использую junit-platform-gradle-plugin.


person igr    schedule 19.09.2017    source источник
comment
JUnit5 определяет задачу только для исходного набора main. Вы можете увидеть запрос на junit-team/junit5-samples для такого рода поддержка. Вам понадобится новая задача для запуска JUnit. Вы можете увидеть пример того, как вы могли бы настроить его в этот ответ. Я не думаю, что команда JUnit планирует поддерживать его и ждет команды Gradle встроить встроенную поддержку.   -  person mkobit    schedule 20.09.2017
comment
@mkobit Я знаю, что это проблема градиента. спасибо за ссылку, я думаю, что я почти там   -  person igr    schedule 20.09.2017


Ответы (1)


В итоге я удалил плагин и напрямую вызвал ConsoleRunner:

task testIntegration(type: JavaExec, dependsOn: jar) {
    group 'Verification'
    description 'Runs the integration tests.'

    dependencies {
        testRuntime lib.junit5_console
    }

    classpath = sourceSets.testInt.runtimeClasspath
    systemProperties['jar.path'] = jar.archivePath

    main 'org.junit.platform.console.ConsoleLauncher'
    args = ['--scan-classpath', sourceSets.testInt.output.classesDirs.asPath,
            '--reports-dir', "${buildDir}/test-results/testInt"
    ]
}

Кроме того, вот как применить JaCoCo с настройками:

afterEvaluate {
    jacoco {
        applyTo testUnit
        applyTo testIntegration
    }
    testIntegration.extensions.getByName("jacoco").excludes = ['*Test*', '*.?', '*Foo*', 'jodd.asm5.*', '*.fixtures.*']
}

Для более подробной информации см. файл сборки Jodds

person igr    schedule 20.09.2017