RFR: 8366678: Use JUnit in test/langtools/tools/javac [v2]
Christian Stein
cstein at openjdk.org
Thu Sep 4 22:28:43 UTC 2025
On Thu, 4 Sep 2025 15:39:58 GMT, Christian Stein <cstein at openjdk.org> wrote:
>> Well, uncommon as it is claimed to be, it already appeared twice in the set of tests in javac 😕
>
> I think, these two classes started out as normal programs; using `main` methods as their entry-points. In such programs, you can and need to create instances to your liking, even of the static program-defining class.
> Using a framework, shifts the instantion duty to (most of the time) reflection, under the framework's control. That way, `@Before[After]All|Each` and other lifecycle callbacks are realized. Usually, you then never write `new MyObjectTest()` with your test code. That would be "detached" test instances; not par-taking in the test lifecycle.
>
> When those two test classes were migrated to use TestNG, they ended up with framework-managed instances (where @Test-annotated methods serve as entry-points) asserting stuff against "detached" instances created by the test logic.
>
> Therefore, I suggest to "just" help JUnit here to select the correct constructor - which TestNG does by default.
Turns out that we can delete the extra constructor from the test classes and leave only a sole one to use for JUnit and local test needs.
See https://github.com/openjdk/jdk/pull/27046/commits/839b93129bb3318ac659be031b3e296eeaf0ead2 for details.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27046#discussion_r2323647315
More information about the compiler-dev
mailing list