Can I use JUnit5 ClassOrderer to shuffle JUnit4 tests run via junit-vintage engine?

67 views Asked by At

If I use JUnit5 to run legacy JUnit4 tests, is there any way to configure it to use ClassOrderer for those JUnit4 classes? I saw in debugger that in org.junit.jupiter.engine.discovery.AbstractOrderingVisitor#orderChildrenTestDescriptors only JUnit5 tests are returned and processed.

I run tests from gradle, using quite simple config

build.gradle:

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.8.1'

...

test {
    useJUnitPlatform()

    testLogging {
        events "STARTED", "SKIPPED", "PASSED", "FAILED"
        showStackTraces true
        showCauses true
        exceptionFormat "full"
    }
}

junit-platform.properties:

junit.jupiter.testmethod.order.default=org.junit.jupiter.api.MethodOrderer$Random
junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$Random
1

There are 1 answers

2
johanneslink On

No, you can't. @ClassOrderer is an annotation only processed by the Jupiter test engine. You can see that by its package name org.junit.jupiter.api.

Features that build on one engine cannot use features of another one, unless the other engine supports that feature explicitly. Since JUnit vintage is mostly there to allow a smooth migration from JUnit 4 to JUnit 5, there will never be support for Jupiter features in JUnit 4 - unless you build it yourself, of course.