1

I'm trying to order some class tests so Test_Class_1 will run before Test_Class_2. I saw a few post about Jupiter 5.8.0 can do it. It seems to be pretty straightforward, but could not make it work.

I'm following the documentation

https://junit.org/junit5/docs/current/user-guide/#overview

But I must be failing to see something

I have these two test class

@Order(1)
public class Test_1 {
    @Test
    public void test(){
        System.out.println("TEST ONE");
    }
}

and

@Order(2)
public class Test_2 {
    @Test
    public void test(){
        System.out.println("TEST TWO");
    }
}

I have the junit-platform.properties (in test/resources) with

junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$OrderAnnotation

and a very simple pom.xml

<dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.0</version>
            <scope>test</scope>
        </dependency>
</dependencies>
  • Also seeing the same behavior. Did you ever figure out a solution? – After_Sunset Apr 25 '22 at 17:36
  • Not really. I think at the end I refactored everything. For me I needed this for a legacy project, so I didn't want to spend much time refactoring everything, but in general I would say that Tests (and more even test classes) should not be dependent between each other. So if you can change the code to not need this, I would recommend to do that – Santiago Purucker May 13 '22 at 07:57

1 Answers1

0

Using a Test Suite and adding @TestClassOrder(ClassOrderer.OrderAnnotation.class) to each test class in addition to OPs setup worked for me.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253