Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When only the RepeatedTest method is included in the unit test, BeforeAll is executed after all the methods have been executed in a different order than expected #4071

Closed
GaulleGL opened this issue Oct 14, 2024 · 1 comment

Comments

@GaulleGL
Copy link

GaulleGL commented Oct 14, 2024

JUnit5 version:5.11.1
code:

class HelloWorldTest {

    @BeforeAll
    public static void beforeAll() {
        System.out.println("BeforeAll...");
    }

    @RepeatedTest(2)
    void test() {
        System.out.println("test execute");
    }

    @RepeatedTest(2)
    void test1() {
        System.out.println("test1 execute");
    }

    @AfterAll
    public static void afterAll() {
        System.out.println("AfterAll...");    }
}

Console output:
test execute
test execute
test1 execute
test1 execute
BeforeAll...
AfterAll...

@marcphilipp
Copy link
Member

marcphilipp commented Oct 14, 2024

I can confirm that the console output looks like that when executing in IntelliJ IDEA. However, changing the code to include timestamps and sleeps, the shown output is the following:

package example;

import java.time.LocalTime;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;

class HelloWorldTest {

	@BeforeAll
	public static void beforeAll() throws InterruptedException {
		System.out.println(LocalTime.now() + " - BeforeAll...");
		Thread.sleep(100);
	}

	@RepeatedTest(2)
	void test() throws InterruptedException {
		System.out.println(LocalTime.now() + " - test execute");
		Thread.sleep(100);
	}

	@RepeatedTest(2)
	void test1() throws InterruptedException {
		System.out.println(LocalTime.now() + " - test1 execute");
		Thread.sleep(100);
	}

	@AfterAll
	public static void afterAll() throws InterruptedException {
		System.out.println(LocalTime.now() + " - AfterAll...");
		Thread.sleep(100);
	}
}
15:35:59.260741054 - test execute
15:35:59.368766545 - test execute
15:35:59.472213945 - test1 execute
15:35:59.574471085 - test1 execute
15:35:59.141689507 - BeforeAll...
15:35:59.677100729 - AfterAll...

As you can see, @BeforeAll method is clearly executed prior to running any (repeated) test.

Thus, this seems to be a bug in IntelliJ IDEA. In fact, a similar issue was reported last week by @wind57 in #4047.

@GaulleGL @wind57 Could one of you please raise an issue directly in the IntelliJ IDEA issue tracker?

@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants