0

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
tporeba
  • 867
  • 10
  • 23

1 Answers1

1

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.

johanneslink
  • 4,877
  • 1
  • 20
  • 37
  • I was afraid of that. As a one-off trick I used debugger to shuffle `org.junit.platform.engine.support.descriptor.AbstractTestDescriptor#children` and it worked. But for a less hacky solution I guess I would need to build a fork of junit-vintage engine. – tporeba Dec 02 '22 at 17:01
  • 1
    Or just migrate the testclass you want to shuffle to Jupiter. – johanneslink Dec 02 '22 at 20:30