Using Store

Learn how to use the Store and TimingExtension annotations in JUnit 5.

We'll cover the following

The Store annotation

The Store annotation is useful for storing data for stateful extensions. The TimingExtension in the code below records the execution time for each test method. The execution time is published as a report entry. The namespace of the store is created from the test class object. The key in the store is the test method object. In the beforeTestExecution method in lines 5–9, we save the current timestamp to the store. In the afterTestExecution method in lines 11–19, we get the start timestamp from the store and calculate the duration, then publish the duration using publishReportEntry.

Get hands-on with 1200+ tech skills courses.