RFR: 8301701 : java/net/DatagramSocket/DatagramSocketMulticasting.java should be hardened [v2]

Christian Stein cstein at openjdk.org
Tue Feb 14 15:42:28 UTC 2023


On Tue, 14 Feb 2023 15:02:51 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Darragh Clarke has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   cleanup based on feedback
>
> test/jdk/java/net/DatagramSocket/DatagramSocketMulticasting.java line 66:
> 
>> 64: import static org.junit.jupiter.api.Assumptions.assumeTrue;
>> 65: 
>> 66: @TestInstance(TestInstance.Lifecycle.PER_CLASS)
> 
> Is this needed?

I don't think so.

One test instance per test class is useful for when having multiple test methods that want to share state in instance fields. Here, we have a single test method and no shared state.

Find details at https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-instance-lifecycle
> If you would prefer that JUnit Jupiter execute all test methods on the same test instance, annotate your test class with `@TestInstance(Lifecycle.PER_CLASS)`. When using this mode, a new test instance will be created once per test class. Thus, if your test methods rely on state stored in instance variables, you may need to reset that state in `@BeforeEach` or `@AfterEach` methods.

-------------

PR: https://git.openjdk.org/jdk/pull/12513


More information about the net-dev mailing list