如何在Gradle 4.5中使用JUnit 5。

huangapple go评论92阅读模式
英文:

How to use junit5 with gradle 4.5

问题

由于某种原因,我不得不在我的项目中将 Gradle 版本从 4.10 降级到 4.5,但我的所有测试都是使用 JUnit 5 编写的。看起来在 Gradle 4.5 中不支持 JUnit 5,因为 useJUnitPlatform() 是在 Gradle 4.6 中引入的。

我想知道是否有一些方法可以在 Gradle 4.5 中使用 JUnit 5。

提前感谢您的帮助。

英文:

For some reason I have to downgrade my gradle version from 4.10 to 4.5 in my project, but all of my test was written in junit5. It seems junit5 is not supported in gradle 4.5 because useJUnitPlatform() is introduced in gradle 4.6.

I wander is there some workaround to use junit5 with gardle4.5.

Thanks in advance.

答案1

得分: 0

经过一些研究,我发现在 4.6 之前的 gradle 版本中,已经提供了一个插件来帮助编写 JUnit 5 测试,该插件名为 junit-platform-gradle-plugin

以下是我 build.gradle 文件的主要部分:

buildscript {
    dependencies {
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.2.0"
    }
}
allprojects {
    ...
    apply plugin: 'org.junit.platform.gradle.plugin'
}
英文:

After some research, I found gradle has provided a plugin to help write junit5 Test before 4.6 which is junit-platform-gradle-plugin.

Here is the main part of my build.gradle

buildscript {
    dependencies {
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.2.0"
    }
}
allprojects {
    ...
    apply plugin: 'org.junit.platform.gradle.plugin'
}

huangapple
  • 本文由 发表于 2020年9月27日 12:44:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/64084882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定