Skip to content

Junit4 rule testutil migration #3031

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vogella
Copy link
Contributor

@vogella vogella commented Jun 8, 2025

No description provided.

@vogella vogella force-pushed the junit4-rule-testutil-migration branch from 137027c to 1b9aa7c Compare June 8, 2025 17:05
import org.eclipse.core.runtime.jobs.Job;

/**
* JUnit 4 rule to clean up state that can otherwise leak through SWT between
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m by far not an expert. Aren’t we trying to get all the tests to be junit5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step by step yes. This is not this step :-)

Copy link
Member

@HannesWell HannesWell Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m by far not an expert. Aren’t we trying to get all the tests to be junit5?

In general yes, but as Lars said, probably in another step.

For JUnit-5 the strategy is a bit different, but not actually quite simple: One can provide custom org.junit.jupiter.api.extension.Extension implementations that are then use decoratively by adding

@org.junit.jupiter.api.extension.ExtendWith(MyExtension.class)

to the tests that should use it. The sub-interfaces of Extension define callbacks, that are then called at the corresponding time, if a custom extension implements it, for example the AfterAllCallback is called after all test cases of a class have run (similar to methods annotated with @AfterAll). Of course there are more options.

That being said, I wonder if TestUtilCleanupRule should be it's own top-level class that even duplicates methods from TestUtil. I think it would be better to define TestUtilCleanupRule as static nested classes in TestUtil, you could just name it CleanupRule and use it as TestUtil.CleanupRule (then we could have more rules too).
This would also allow to have a corresponding JUnit-5 extension in parallel as static nested class and would allow easy step-by-step migration of tests.
I'm pretty sure that technically it is possible for JUnit-4 Rules and JUnit-5 extensions to be defined as static nested class. Of course it, also works as separate class, but I think it's not worth the extra file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the rule to TestUtil, please have a look @HannesWell if I did as suggested by you

@merks
Copy link
Contributor

merks commented Jun 8, 2025

Would all the direct calls to cleanUp be cleaned up and would this kick in after the tear down of each test?

Copy link
Contributor

github-actions bot commented Jun 8, 2025

Test Results

 2 778 files  +103   2 778 suites  +103   1h 36m 33s ⏱️ + 13m 8s
 7 927 tests ±  0   7 699 ✅ ±  0  228 💤 ± 0  0 ❌ ±0 
23 334 runs  +561  22 588 ✅ +486  746 💤 +75  0 ❌ ±0 

Results for commit bb8824a. ± Comparison against base commit 600c8bb.

♻️ This comment has been updated with latest results.

@vogella
Copy link
Contributor Author

vogella commented Jun 9, 2025

Would all the direct calls to cleanUp be cleaned up and would this kick in after the tear down of each test?

The after method is triggered after each test, if this rule is used.

@vogella vogella force-pushed the junit4-rule-testutil-migration branch 2 times, most recently from a36325b to 0cd32ee Compare June 10, 2025 10:43
@vogella
Copy link
Contributor Author

vogella commented Jun 10, 2025

@HannesWell you suggested the rule. What do you think?

@vogella vogella force-pushed the junit4-rule-testutil-migration branch from 0cd32ee to 4bfa999 Compare June 11, 2025 13:14
In eclipse-platform#3029 it
was suggested to add a rule, this is the rule. It is applied to the
tests.

Some tearDown methods did also spin the event loop, that is not
necessary as the rule does this already.
@vogella vogella force-pushed the junit4-rule-testutil-migration branch from 4bfa999 to bb8824a Compare June 12, 2025 09:34
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

Successfully merging this pull request may close these issues.

3 participants