On Wed, 18 Feb 2026 14:10:44 GMT, Alan Bateman <[email protected]> wrote:
>> This is a first step that converts all tests directly located in the >> test/jdk/java/net/httpclient directory and which depend on ITestContext (a >> TestNG API) to use JUnit instead. >> >> Usage of ITestContext is replaced by registering a TestWatcher which can >> make JUnit stop at the first failure. >> The proposed change is mostly mechanical - with the exception of >> SpecialHeadersTest which is now also testing HTTP/3. >> Some logging in a few of the tests has also been improved. >> >> This is a test change only. > > test/jdk/java/net/httpclient/ForbiddenHeadTest.java line 88: > >> 86: import org.junit.jupiter.params.provider.MethodSource; >> 87: >> 88: @TestInstance(TestInstance.Lifecycle.PER_CLASS) > > I see this is added to a lot of tests. Have you dug into why this is needed? > Just wondering if there are method sources (for parameterize tests) that are > instance rather than static methods or what is the reason. When using [TestInstance.Lifecycle.PER_CLASS](https://docs.junit.org/5.0.0/api/org/junit/jupiter/api/TestInstance.html) then a single instance of the class will be used to invoke all test methods. It makes it possible to use `@BeforeAll` `@AfterAll` to setup and teardown objects/variables that all tests methods depend on. Typically in the `HttpClient` tests we use that to start, and then stop, the `HttpServer` instances that all test methods will interact with. AFAIU that was the default with TestNG - but the JUnit default is to create one instance of the test class for each test method invocation. Using `TestInstance.Lifecycle.PER_CLASS` makes it easier to migrate from TestNG to JUnit. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29786#discussion_r2822668900
