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

@BeforeEach and @AfterEach aren't reliably executed around dynamic tests #2360

Closed
ogregoire opened this issue Jul 23, 2020 · 2 comments
Closed

Comments

@ogregoire
Copy link

ogregoire commented Jul 23, 2020

@BeforeEach and @AfterEach aren't executed around each dynamic test. They are executed only once per @TestFactory. I would expect that they are reliably run around each dynamic test.

I tested on both IntelliJ 2020.1.3 and Maven 3.6.1. What's baffling is that the results are different on each platform.

On IntelliJ, with the snippet below, I get the following output:

before
after
Hello
World

On Maven, I get the following output:

before
Hello
World
after

I would expect that @BeforeEach and @AfterEach are executed around each test, dynamic or not:

before
Hello
after
before
World
after

Steps to reproduce

import java.util.stream.Stream;
import org.junit.jupiter.api.*;
public class DynamicTestTest {

	@BeforeEach
	void beforeEach() {
		System.out.println("before");
	}
	@AfterEach
	void afterEach() {
		System.out.println("after");
	}

	@TestFactory
	Stream<DynamicTest> tests() {
		return Stream.of("Hello", "World")
				.map(word -> DynamicTest.dynamicTest(word, () -> System.out.println(word)));
	}

}

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter 5.7.0-M1, Platform 1.7.0-M1
  • Build Tool/IDE: Maven (3.6.1), IntelliJ (2020.1.3)
@ogregoire
Copy link
Author

ogregoire commented Jul 23, 2020

Well, thank you GitHub, I searched for the same issue before creating this one but couldn't find using my search terms. At least Google helped, only after I created this issue. It can be closed as a duplicate of #378.

@marcphilipp
Copy link
Member

@ogregoire No worries! 🙂

will8ug added a commit to will8ug/java-language-feature-tests that referenced this issue Feb 22, 2024
There seems to be bugs in org.junit.jupiter.api.BeforeEach of JUnit 5 at this moment.
It cannot guarantee the annotated method being excuted before each test method.

References:
- junit-team/junit5#2360
- junit-team/junit5#378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants