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

Closed
lubomsky opened this issue Feb 20, 2025 · 4 comments
Closed

Conditional annotations beyond test method/class #4326

lubomsky opened this issue Feb 20, 2025 · 4 comments

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

Copy link

github-actions bot commented Mar 8, 2025

If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed.

@lubomsky
Copy link
Author

It's all about the readability and convention (I like to have single-responsible methods in my test framework).
For example I have one parametrized test to upload file and then check the app behavior.
But for 1 of 20 cases I need to change something just before uploading.
And after another 1 of 20 cases I need to clean something.

In fact, EnabledIf etc could also be done with an if statement....

@marcphilipp
Copy link
Member

Team decision: We don't think this would be a good fit with the Jupiter programming model. In light of that, we're closing this issue. However, should there be considerable interest from the community we're happy to reconsider.

@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2025
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