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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    Collects the actual outputs and evaluation results a DatasetSource test 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable)
     
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
    Supports an optional DatasetRunExtension.DatasetItemRecorder test-method parameter.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
    • handleTestExecutionException

      public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) throws Throwable
      Specified by:
      handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
      Throws:
      Throwable
    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterEach in interface org.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 optional DatasetRunExtension.DatasetItemRecorder test-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:
      supportsParameter in interface org.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:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException