我在读Junit 5用户指南。它将带我到一个JUnit 5木星级样品,这是在Gradle中使用Junit 5的一个最简单的例子。在build.gradle文件中,有两个依赖项,junit-jupiter和junit-bom。在test任务中,它还调用useJUnitPlatform()函数。
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform('org.junit:junit-bom:5.7.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}据我所知,junit-jupiter是一个聚集的工件,它可以提取以下三个工件,
所以我想junit-jupiter已经足够在我的项目中运行JUnit木星了(如果我错了,请纠正我)。我想知道什么是junit-bom,,,,,,,,谢谢大家:)
发布于 2021-04-30 05:17:08
junit-bom是JUnit的材料清单(BOM)。当包含此BOM时,它将确保为您对齐和管理所有JUnit 5依赖版本。您可以作为这篇文章的一部分找到有关BOM概念的更多信息。
这就是为什么在导入junit-jupiter时不必指定版本的原因
// with the BOM, no version needed
testImplementation('org.junit.jupiter:junit-jupiter')
// when using no BOM, version info is needed
testImplementation('org.junit.jupiter:junit-jupiter:5.7.1')如果您从同一个项目导入多个依赖项,您将看到BOM的好处。当只使用一个依赖项时,它可能看起来是多余的:
// only define the version at a central place, that's nice
testImplementation(platform('org.junit:junit-bom:5.7.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation('org.junit.vintage:junit-vintage-engine') // when you want to also run JUnit 3 + 4 testsuseJUnitPlatform()指示分级测试任务使用JUnit平台执行测试。这是必需的。
在您的示例中,您有一个最低限度的工作设置,可以在Gradle项目中使用JUnit 5。您可以做的是删除junit-bom并自己添加版本信息:
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.7.1')
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}但我会坚持JUnit团队的建议,以及他们在GitHub上的示例项目。
https://stackoverflow.com/questions/67328406
复制相似问题