Add base class and infrastructure support for JUnit5/Jupiter#16027
Open
dweiss wants to merge 72 commits intoapache:mainfrom
Open
Add base class and infrastructure support for JUnit5/Jupiter#16027dweiss wants to merge 72 commits intoapache:mainfrom
dweiss wants to merge 72 commits intoapache:mainfrom
Conversation
…radle/ junit uses.
… and compilation, respectively.
…d multiple times).
…d other infrastructure used from within LuceneTestCase's facilities.
Contributor
Author
|
Relate: #13523 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch adds a new class
LuceneTestCaseJupiter, which can be used as a direct replacement for LuceneTestCase to convert test classes to JUnit5/jupiter.The test-framework module exports both junit4 and junit5/jupiter
dependencies.
LuceneTestCaseremains the parent abstract class for JUnit4 tests.LuceneTestCaseJupiteris the parent class to extend from for JUnit5support.
please read
There are some key things to observe here:
methods must be annotated with
@Test. Method prefixtest*is not sufficient. Methods that are namedtest*but are not testswill cause validation errors at runtime (there is a test for this...).
random()method on the parentclass, even though it is there. Add a
Randomparameter to your test methodsor callbacks - it will be automatically injected by the test framework. See the
memorymodule tests for some examples.
@BeforeEach,@AfterEachand other junit5-specific callbackannotations instead of
setUpandtearDownmethods. These methods are also there, but they should be deprecated and removed at some point.called
LuceneTestCaseParentbut you should reference them eitherwithout an explicit type or via the type of the parent class
for your test framework of choice. The parent class may be removed in the future.
This patch should work as a drop-in-replacement for any subproject using test-framework. A lot of (human) thought went into making sure both the junit4 and junit5 base class work pretty much the same way (there are still some pieces missing but they are not critical).
what next?
Now, if we want to move forward and actually convert all the existing tests to junit5 (and eventually drop junit4) this becomes a more problematic issue because it affects all the downstream projects (solr, elasticsearch) - any tests inheriting from test framework util's "base" classes (like the base class for token filters, etc.) will require updating. If they do non-trivial things, the update may be non-trivial too.
discussion
It took me an enormous amount of time to get this to work with both frameworks at the same time. Not everything is pretty internally but I don't see how certain things can be solved while keeping backward compatibility (and without changing a lot of existing codebase).
Now... For all the benefits junit5 provides (there are many nice things about it), I also think there is not that much visible improvement... I mean - for all the bells and whistles of junit5, it's still just a test framework for running test cases. We can't utilize parallel tests (because we use static contexts everywhere), we don't really do any fancy things. It's mostly the same. If you think this is complicating things with no clear benefit, please do speak up.