首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoClassDefFoundError:史波克2.0中的org.junit.rules.TestName:

NoClassDefFoundError:史波克2.0中的org.junit.rules.TestName:
EN

Stack Overflow用户
提问于 2021-09-27 15:18:23
回答 1查看 468关注 0票数 1

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

代码语言:javascript
复制
testImplementation group: 'org.spockframework', name: 'spock-core', version: '2.0-groovy-2.5'

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

代码语言:javascript
复制
':compileTestGroovy'. Caused by: java.lang.NoClassDefFoundError: org.junit.rules.TestName

据我所知,Spock 2.0不再包含这个类所需的内部依赖关系。我在样本工程中显式地添加了junit-4依赖项。

代码语言:javascript
复制
testImplementation group: 'org.spockframework', name: 'spock-junit4', version: '2.0-groovy-2.5'

这就解决了上述问题。但是现在我得到了“测试事件没有收到”错误。

有谁能解释一下,为了让新的斯波克启动测试,还应该做些什么?

更新添加build.gradle。测试已经从以下配置开始:

代码语言:javascript
复制
    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
        }
    }
}

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

代码语言:javascript
复制
org.spockframework.runtime.model.FeatureInfo.getDescription()Lorg/junit/runner/Description;
java.lang.NoSuchMethodError: org.spockframework.runtime.model.FeatureInfo.getDescription()Lorg/junit/runner/Description;
EN

回答 1

Stack Overflow用户

发布于 2021-09-27 16:56:00

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

代码语言:javascript
复制
test {
  useJUnitPlatform()
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69349149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档