NoClassDefFoundError: org.junit.rules.TestName in Spock 2.0:



我正在尝试将我的测试项目从Spock 1.3更新到2.0:

testImplementation group: 'org.spockframework', name: 'spock-core', version: '2.0-groovy-2.5'

但是在测试开始时得到以下错误:

':compileTestGroovy'. Caused by: java.lang.NoClassDefFoundError: org.junit.rules.TestName

据我所知,Spock 2.0不再包含这个类所需的内部依赖。我显式地添加了junit-4依赖项,就像在示例项目中一样:

testImplementation group: 'org.spockframework', name: 'spock-junit4', version: '2.0-groovy-2.5'

解决了上述问题。但是现在我得到的是" test events were not received "错误。

谁能解释一下,为了让新的斯波克发射测试,还应该改变什么?

添加build.gradle。使用以下配置启动测试:

buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
}
dependencies {
classpath "io.qameta.allure:allure-gradle:2.8.1"
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.24.5'
classpath "io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE"
}
}
plugins {
id "idea"
id "groovy"
id "io.qameta.allure" version "2.5"
}

apply plugin: "application"
apply plugin: "groovy"
apply plugin: 'maven-publish'
apply plugin: 'io.qameta.allure'

sourceCompatibility = 1.8
dependencies {
compile 'org.codehaus.groovy:groovy:2.5.2'
implementation group: 'org.codehaus.groovy', name: 'groovy-dateutil', version: '2.5.2'
implementation group: 'org.codehaus.groovy', name: 'groovy-json', version: '2.5.2'
compile "org.testng:testng:6.9.8"
compileOnly "io.micronaut:micronaut-bom:$micronautVersion"
implementation "io.micronaut:micronaut-security-jwt"
implementation "io.micronaut:micronaut-inject-groovy"
implementation "io.micronaut:micronaut-validation"
implementation "io.micronaut:micronaut-http-server-netty"
implementation "io.micronaut:micronaut-http-client"
compile "io.micronaut:micronaut-aop"
implementation "io.micronaut:micronaut-runtime"
compile 'ch.qos.logback:logback-classic:1.1.7'
compile "org.aspectj:aspectjweaver:1.9.2"
testImplementation "io.micronaut.test:micronaut-test-spock"
testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
testCompile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.0.0'
testImplementation group: 'org.spockframework', name: 'spock-core', version: '2.0-groovy-2.5'
testImplementation group: 'org.spockframework', name: 'spock-junit4', version: '2.0-groovy-2.5'
testCompile("org.gebish:geb-spock:3.4") {
/* https://github.com/micronaut-projects/micronaut-test/issues/100 */
exclude group: "org.codehaus.groovy", module: "groovy-all"
}
testCompile "org.seleniumhq.selenium:selenium-java:3.141.59"
compile "com.codeborne:selenide:4.12.0"
testCompile 'org.slf4j:slf4j-jdk14:1.7.25'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
implementation group: 'io.qameta.allure', name: 'allure-spock', version: '2.15.0'
testCompile group: 'org.monte', name: 'screen-recorder', version: '0.7.7'
compile group: 'org.springframework', name: 'spring-messaging', version: '4.3.27.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '4.3.27.RELEASE'
compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
compile group: 'org.apache.tomcat', name: 'tomcat-websocket', version: '8.0.20'
compile group: 'io.github.http-builder-ng', name: 'http-builder-ng-core', version: '1.0.4'
driver group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'

}

test {
exclude '**/*/**'
}

allure {
version = '2.15.0'
aspectjweaver = true
autoconfigure = false
resultsDir = file("$buildDir/allure-results")
reportDir = file("$buildDir/allure-report")
useSpock {
version = '2.15.0'
}
useTestNG {
version = '2.15.0'
}
}
task apiTest(type: Test, group: 'verification', dependsOn: ['fetchTestFiles']) {
outputs.upToDateWhen { false }
include '**/api/**'
getFilter().setFailOnNoMatchingTests(false)
useJUnitPlatform()
List<String> testNamePatterns = System.getProperty('API_TEST_NAME_PATTERNS')?.split(' ')?.findAll { it }
if (testNamePatterns) {
println("GOT API_TEST_FILTER PROPAGATED $testNamePatterns")
filter {
testNamePatterns.each {
includeTestsMatching(it)
}
}
}
doFirst {
def weaver = configurations.compile.find { it.name.contains("aspectjweaver") }
jvmArgs = jvmArgs << "-javaagent:$weaver"
project.gradle.startParameter.systemPropertiesArgs.entrySet().collect() {
systemProperty it.key, it.value
}
}
}

现在,我得到报告错误,这与最初的问题无关。我是否假设当前的allu - spock实现不支持spock 2.0?:

org.spockframework.runtime.model.FeatureInfo.getDescription()Lorg/junit/runner/Description;
java.lang.NoSuchMethodError: org.spockframework.runtime.model.FeatureInfo.getDescription()Lorg/junit/runner/Description;

我猜是因为你没有提供你的build.gradle,但我很确定你忘了添加

test {
useJUnitPlatform()
}

最新更新