我们不能用Junit 5和Spock框架一起在一个吊带项目中运行测试用例?
我们尝试将https://www.baeldung.com/junit-5-gradle中的依赖项添加到我们的gradle文件中。Gradle版本为4.10.3和Junit 5。
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenCentral()
maven {
url "http://repo.fusesource.com/nexus/content/groups/public/"
}
maven {
url "https://repository.jboss.org/nexus/content/groups/public"
}
jcenter()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '4.2.2'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
testCompile(
'org.codehaus.groovy:groovy-all:2.4.8',
'org.spockframework:spock-core:1.0-groovy-2.4',
'org.jmockit:jmockit:1.8',
'junit:junit:4.12'
)
testRuntime(
'cglib:cglib:2.2.2',
'com.athaydes:spock-reports:1.2.7'
)
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testCompileOnly 'junit:junit:4.12'
}
test {
useJUnitPlatform()
testLogging { showStandardStreams = true }
}我已经创建了两个测试用例,一个是使用spock框架,另一个是使用junit 5。但是当我使用gradlew -test时,它只运行用Junit 5编写的测试用例。下面是构建路径。

发布于 2019-08-21 16:12:29
您需要Vintage测试引擎来执行史波克测试,因为它们是基于JUnit 4的,并且您需要木星测试引擎来执行JUnit木星测试。
因此,您需要两个引擎的依赖关系。
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'我还建议您升级到JUnit 5.5.1 (也就是最新的和最好的)。
https://stackoverflow.com/questions/57585371
复制相似问题