0

运行 gradle test 时出现错误

Caused by: java.lang.IllegalArgumentException: Received a failure event for test with unknown id '16.3'. Registered test ids: '[16.1, 16.2, :app:test]

仅当测试包含系统规则添加的功能时才会发生此错误。例如

@Test
    void sysOutTest() {
        System.out.print("hello world");
        assertEquals("hello world", systemOutRule.getLog());
    }

我的 build.gradle 文件如下所示:

plugins {
    
    id 'application'
    id 'jacoco'
}

repositories {
    
    jcenter()
}

dependencies {

    

    testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.1.0'

}

application {
    // Define the main class for the application.
    mainClass = 'package.App'
}

test {
    useJUnitPlatform()
    //scanForTestClasses false (This was in here and is commented out as originaly gradle was not detecting tests that were in the style of Junit4)
    finalizedBy jacocoTestReport
}

run{
    standardInput = System.in
}

jacocoTestReport {
    reports {
        html.enabled = true
        csv.enabled = true
    }
}

sourceSets {
    test {
        java {
            srcDir 'test'
        }
    }
    main {
        java {
            srcDir 'main'
        }
    }
}

需要明确的是,当文件没有使用 SystemRules 的测试时,测试工作正常。

我(愚蠢地)已经使用 SystemRules 编写了所有测试,所以我宁愿找到一种方法让它工作,而不是从头开始。

谢谢你的帮助

4

1 回答 1

0

我只需要在测试之前公开。所有其他不使用系统规则的测试都是公开的。

@Test
    public void sysOutTest() {
        System.out.print("hello world");
        assertEquals("hello world", systemOutRule.getLog());
    }
于 2021-09-23T02:19:11.520 回答