如何运行特定(超出构建周期)使用Gradle进行Junit5测试 [英] How to run particular (out of build cycle) Junit5 tests using Gradle

查看:116
本文介绍了如何运行特定(超出构建周期)使用Gradle进行Junit5测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将测试移至junit5,这些测试将与Gradle一起运行。在一个与我一起工作的项目中,有单元测试和一些必须按需运行的特定测试(从特定的Gradle任务我想)。



单元测试很清楚。 Gradle插件为此添加了支持。
但我无法找到一种方法为我的需求定义另一个测试任务
我在Junit5插件源中搜索并发现没有任何特定的类用于此目的。 Gradle插件只是简单地设置了一个JavaExec任务,然后运行它。



因此,似乎没有可见的方式来定义我自己的
任务-in type like this


任务myTask(类型:Junit5TestRunner)
这里我们设置了一个任务


任何想法如何实现? c>工件并配置控制台启动器以满足您的需要。像:

 配置{
独立
}

依赖关系{
standalone'org.junit.platform:junit-platform-console-standalone:1.0.0-SNAPSHOT'
}

任务downloadJUnitPlatformStandalone(type:Copy){
from将
独立成$ buildDir / junit-platform-standalone
eachFile {println(standalone) - >+ it.file.name}
}

任务runJUnitPlatformStandalone(类型:JavaExec,dependsOn:downloadJUnitPlatformStandalone){
jvmArgs'-ea'
jvmArgs'-Djava.util.logging.config.file = src / test / logging.properties'
classpath = fileTree(dir:$ buildDir / junit-platform-standalone,include:'* .jar')+ project.sourceSets.test.runtimeClasspath
main'org.junit.platform.console。 ConsoleLauncher'
args + ='--scan-class-path'
args + ='--disable-ansi-colors'
args + ='--details = tree'
args + = - 报告s-dir = $ project.testReportDir


test.dependsOn runJUnitPlatformStandalone

来源 junit-platform-standalone。 gradle 或备用(仅木星)依赖关系 jupiter.gradle



没有自己的配置和下载: https://discuss.gradle.org/t/junit-5-jupiter-platform-snapshot-console-launcher-task/19773/ 2


I am moving tests to junit5 that are going to be run with Gradle. In a project I work with there are unit tests and some specific tests that must be run on demand (from particular Gradle tasks I suppose).

It is clear about unit tests. Gradle plugin adds a support for that. But I could not find a way to define another test task for my needs I searched in Junit5 plugin source and found out that there are no any particular class for that purpose. The Gradle plugin simply sets up a JavaExec task and then runs it.

Therefore it seem that there are no visible ways to define my own task of the built-in type like this

task myTask(type: Junit5TestRunner) Here we set up a task

Any ideas how it can be done ?

解决方案

Define a new configuration, depend on junit-platform-console-standalone artifact and configure the console launcher to your needs. Like:

configurations {
    standalone
}

dependencies {
    standalone 'org.junit.platform:junit-platform-console-standalone:1.0.0-SNAPSHOT'
}

task downloadJUnitPlatformStandalone(type: Copy) {
    from configurations.standalone
    into "$buildDir/junit-platform-standalone"
    eachFile { println " (standalone) -> " + it.file.name }
}

task runJUnitPlatformStandalone(type: JavaExec, dependsOn: downloadJUnitPlatformStandalone) {
    jvmArgs '-ea'
    jvmArgs '-Djava.util.logging.config.file=src/test/logging.properties'
    classpath = fileTree(dir: "$buildDir/junit-platform-standalone", include: '*.jar') + project.sourceSets.test.runtimeClasspath
    main 'org.junit.platform.console.ConsoleLauncher'
    args += '--scan-class-path'
    args += '--disable-ansi-colors'
    args += '--details=tree'
    args += "--reports-dir=$project.testReportDir"
}

test.dependsOn runJUnitPlatformStandalone

Source junit-platform-standalone.gradle or alternate (Jupiter-only) dependencies jupiter.gradle.

Without own configuration and download: https://discuss.gradle.org/t/junit-5-jupiter-platform-snapshot-console-launcher-task/19773/2

这篇关于如何运行特定(超出构建周期)使用Gradle进行Junit5测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆