-
Notifications
You must be signed in to change notification settings - Fork 219
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
base: master
Are you sure you want to change the base?
Junit4 rule testutil migration #3031
Conversation
137027c
to
1b9aa7c
Compare
import org.eclipse.core.runtime.jobs.Job; | ||
|
||
/** | ||
* JUnit 4 rule to clean up state that can otherwise leak through SWT between |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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. |
a36325b
to
0cd32ee
Compare
@HannesWell you suggested the rule. What do you think? |
0cd32ee
to
4bfa999
Compare
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.
4bfa999
to
bb8824a
Compare
No description provided.