RFR: CODETOOLS-7902838: JMH: Don't use fail() inside a try-catch catching an AssertionError

Henri Tremblay github.com+1216819+henri-tremblay at openjdk.java.net
Tue Mar 9 23:01:13 UTC 2021


On Tue, 9 Mar 2021 20:52:15 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> jmh-core-it/src/test/java/org/openjdk/jmh/it/fails/FailingBenchmarkBenchSetupTest.java line 76:
>> 
>>> 74:             new Runner(opt).run();
>>> 75: 
>>> 76:             Assert.fail("Should have failed");
>> 
>> If you want to have fun, with JUnit 4.13.2 (see #24) you can use `assertThrows`. This code will become
>> 
>> public void invokeAPI() throws RunnerException {
>>             Options opt = new OptionsBuilder()
>>                     .include(Fixtures.getTestMask(this.getClass()))
>>             RunnerException exception = assertThrows(() -> new Runner(opt).run());
>>             assertEquals(exception.getMessage(), "xxxxx"); // this is the bonus, checking it's the right message
>> }
>
> True, except that JMH codebase is still at JDK 7 compatibility, so no nice lambdas, and this gets much less appealing.

Arg... Forgot that

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

PR: https://git.openjdk.java.net/jmh/pull/25


More information about the jmh-dev mailing list