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

Conditional annotations beyond test method/class #4326

Open
lubomsky opened this issue Feb 20, 2025 · 1 comment
Open

Conditional annotations beyond test method/class #4326

lubomsky opened this issue Feb 20, 2025 · 1 comment

Comments

@lubomsky
Copy link

I use JUnit as a runner for tests written in playwright.
For debugging purposes I want to do something only when some condition is met, for example some property is true.

Naturally I went with:

@BeforeAll
@EnabledIf("someCondition")
fun `do something once`() {
 // some setup
}


@BeforeEach
@EnabledIf("someCondition")
fun `do something every time`() {
 // something to do
}

private fun someCondition() = true

but this is not working - as expected after reading the javadoc.

Is it possible to add such a functionality?
Or maybe there is a different way to handle that?

@marcphilipp
Copy link
Member

What would be the benefit of doing this rather can using a regular if statement?

@BeforeAll
fun `do something once`() {
  if (someCondition()) {
    // some setup
  }
}


@BeforeEach
fun `do something every time`() {
  if (someCondition()) {
    // something to do
  }
}

private fun someCondition() = true

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