Package dev.dokimos.junit
Class DatasetRunExtension
java.lang.Object
dev.dokimos.junit.DatasetRunExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestExecutionExceptionHandler,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
public class DatasetRunExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.TestExecutionExceptionHandler, org.junit.jupiter.api.extension.ParameterResolver
Opens and reports a
Reporter run for each DatasetSource test method.
Reporting is opt-in. The extension looks for a static field of type Reporter annotated
with DatasetReporter on the test class. When none is found, NoOpReporter is used
and the test runs exactly as a plain parameterized test would.
When a reporter is present, one run is opened per @DatasetSource method: the run starts
before the first invocation, each parameterized invocation is reported as an ItemResult,
and the run is completed after the last invocation with RunStatus.SUCCESS when every
invocation passed or RunStatus.FAILED when at least one threw. The reporter is always
flushed after completion. The extension never closes a reporter supplied
via DatasetReporter; that lifecycle belongs to the test class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCollects the actual outputs and evaluation results aDatasetSourcetest body produced for one parameterized invocation.Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) voidhandleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Supports an optionalDatasetRunExtension.DatasetItemRecordertest-method parameter.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
DatasetRunExtension
public DatasetRunExtension()
-
-
Method Details
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
handleTestExecutionException
public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) throws Throwable - Specified by:
handleTestExecutionExceptionin interfaceorg.junit.jupiter.api.extension.TestExecutionExceptionHandler- Throws:
Throwable
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException Supports an optionalDatasetRunExtension.DatasetItemRecordertest-method parameter. When the test body declares it,afterEach(org.junit.jupiter.api.extension.ExtensionContext)reports the outputs and eval results it captured; otherwise the reported item stays empty.- Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-