Skip to content

Add base class and infrastructure support for JUnit5/Jupiter#16027

Open
dweiss wants to merge 83 commits into
apache:mainfrom
dweiss:jupiter
Open

Add base class and infrastructure support for JUnit5/Jupiter#16027
dweiss wants to merge 83 commits into
apache:mainfrom
dweiss:jupiter

Conversation

@dweiss
Copy link
Copy Markdown
Contributor

@dweiss dweiss commented May 2, 2026

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. LuceneTestCase remains the parent abstract class for JUnit4 tests.
LuceneTestCaseJupiter is the parent class to extend from for JUnit5
support.

please read

There are some key things to observe here:

  • If you decide to inherit from LuceneTestCaseJupiter, all test cases must be proper Jupiter tests, typically this means
    methods must be annotated with @Test. Method prefix
    test* is not sufficient
    . Methods that are named test* but are not tests
    will cause validation errors at runtime (there is a test for this...).
  • You can use parameterized tests, dynamic tests, etc. All these are supported.
  • You must not call the static random() method on the parent
    class, even though it is there. Add a Random parameter to your test methods
    or callbacks - it will be automatically injected by the test framework. See the memory
    module tests for some examples.
  • Use @BeforeEach, @AfterEach and other junit5-specific callback
    annotations instead of setUp and tearDown methods. These methods are also there, but they should be deprecated and removed at some point.
  • Static utility methods have been pulled up to a parent class
    called LuceneTestCaseParent but you should reference them either
    without 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.

dweiss added 30 commits April 12, 2026 21:02
…d other infrastructure used from within LuceneTestCase's facilities.
dweiss and others added 13 commits May 3, 2026 15:09
* deps(java): bump gradle-wrapper from 9.4.1 to 9.5.0

Bumps [gradle-wrapper](https://github.com/gradle/gradle) from 9.4.1 to 9.5.0.
- [Release notes](https://github.com/gradle/gradle/releases)
- [Commits](gradle/gradle@v9.4.1...v9.5.0)

---
updated-dependencies:
- dependency-name: gradle-wrapper
  dependency-version: 9.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update launch scripts, wrapper checksum, an explicit Project reference.

* Add changelog.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dawid Weiss <dawid.weiss@carrotsearch.com>
…apache#16037)

* deps(java): bump org.apache.opennlp:opennlp-tools from 2.5.8 to 2.5.9

Bumps [org.apache.opennlp:opennlp-tools](https://github.com/apache/opennlp) from 2.5.8 to 2.5.9.
- [Release notes](https://github.com/apache/opennlp/releases)
- [Commits](apache/opennlp@opennlp-2.5.8...opennlp-2.5.9)

---
updated-dependencies:
- dependency-name: org.apache.opennlp:opennlp-tools
  dependency-version: 2.5.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Checksums, lockfile.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dawid Weiss <dawid.weiss@carrotsearch.com>
…15971)

Signed-off-by: prithvi <prithvisivasankar@gmail.com>
This speeds up TrieBuilder and reduces its memory footprint by replacing the in-memory object tree with a compact prefix-coded byte buffer during the building phase, and using a frontier-based approach during the saving phase.
)

`TopFieldCollectorManager` had an internal `ArrayList` tracking collectors via `getCollectors()`, which is unused anywhere in Lucene. Consumers are also not expected to call such method, as there is no need to retrieve the collectors that the collector manager created while searching. What matters is the `TopFieldDocs` that `reduce` returns, which in turn `IndexSearcher#search` exposes.

This commit removes the internal list and the public getter method. It also clarifies javadocs: thread-safety is guaranteed for shared internal states (hit counting, minimum score propagation) across collectors, not for `newCollector()` itself which is designed to be called from a single thread.

Resolves apache#15605

Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
…VectorsReader (apache#16043)

This makes getFlatVectorScorer consistent with getRandomVectorScorer, so both take the field name the scorer is for.
@dweiss
Copy link
Copy Markdown
Contributor Author

dweiss commented May 12, 2026

I plan to commit this to main if there are no objections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test-framework JUnit 5 support

4 participants