0

When running gradle test I receive an error

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]

This error only occurs when tests include functionality added by system-rules. For example

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

My build.gradle file looks like this:

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'
        }
    }
}

To be clear, tests work fine when the file has no tests that use SystemRules.

I've (stupidly) already written all my tests using SystemRules, so I would prefer to find a way to make it work instead of starting from scratch.

Thanks for any help

1 Answers1

0

I just needed to put public before my tests. All the other tests that didn't use System rules had public.

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