Gradle使用Junit5进行test

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21845263/article/details/82151977

1.如果是Gradle 4.6及以上版本,则Gradle原生支持Junit5,使用时只需在build.gradle里配置:

test {
useJUnitPlatform()
}

dependency按正常来即可:

dependencies {
testCompile group: ‘org.junit.platform’, name: ‘junit-platform-launcher’, version:’1.2.0’
testCompile group: ‘org.junit.jupiter’, name: ‘junit-jupiter-engine’, version:’5.2.0’
testCompile group: ‘org.junit.vintage’, name: ‘junit-vintage-engine’, version:’5.2.0’
}

具体请看Gradle 4.6的release note: https://docs.gradle.org/4.6/release-notes.html#junit-5-support

2.除此之外如果Gradle版本比较低,可以借助JUnit Platform Gradle 插件来支持Junit5,不过官方已经不再推荐这样了,推荐第一种做法:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath ‘org.junit.platform:junit-platform-gradle-plugin:1.2.0’
}
}
apply plugin: ‘org.junit.platform.gradle.plugin’

猜你喜欢

转载自blog.csdn.net/qq_21845263/article/details/82151977
今日推荐