public class BenchmarkExtension extends Object implements org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback
timestamp = 2018-08-30T16:28:47.701, Elapsed time in MICROSECONDS for canBenchmark = 13213Your own implementation of the
EngineExecutionListener could adopt a different template
for the event string or it could collect and aggregate results for all tests in a test case or it
could write results to somewhere other than the console etc.
By default, elapsed times are reported in TimeUnit.MILLISECONDS but you can use RegisterExtension to choose a different TimeUnit.
Usage example:
@ExtendWith(BenchmarkExtension.class)
public class MyTest {
@Test
public void aTest() {
// ...
}
}
public class MyTest {
// report elapsed times in a non default time unit
@@RegisterExtension
static BenchmarkExtension benchmarkExtension = new BenchmarkExtension(TimeUnit.MICROSECONDS);
@Test
public void aTest() {
// ...
}
}
| Modifier and Type | Field and Description |
|---|---|
static String |
REPORT_EVENT_FORMAT |
| Constructor and Description |
|---|
BenchmarkExtension()
Constructs an instance of this class which will report using the default time unit.
|
BenchmarkExtension(TimeUnit timeUnit)
Constructs an instance of this class which will report using the given
timeUnit. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Gather the elapsed time, using
StopWatch stored by beforeTestExecution(ExtensionContext). |
void |
beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Store a
StopWatch instance against the test method name for use in afterTestExecution(ExtensionContext). |
public static final String REPORT_EVENT_FORMAT
public BenchmarkExtension()
public BenchmarkExtension(TimeUnit timeUnit)
timeUnit.timeUnit - the time unit in which benchmarks will be reportedpublic void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
throws Exception
StopWatch instance against the test method name for use in afterTestExecution(ExtensionContext).beforeTestExecution in interface org.junit.jupiter.api.extension.BeforeTestExecutionCallbackextensionContext - the context in which the current test or container is being
executedExceptionpublic void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
throws Exception
StopWatch stored by beforeTestExecution(ExtensionContext).afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallbackextensionContext - the context in which the current test or container is being
executedExceptionCopyright © 2022. All rights reserved.