Class SnapshotTestContext


  • @API(status=INTERNAL,
         since="1.1.0")
    public final class SnapshotTestContext
    extends Object
    Context object that pertains to the execution of a whole test class which is annotated with EnableSnapshotTests.
    Since:
    1.1.0
    Author:
    Simon Taddiken
    • Method Detail

      • isSnapshotParameter

        public boolean isSnapshotParameter​(Class<?> type)
        Determines whether the parameters with the given type are eligible for injecting the object that is created by createSnapshotTestFor(Method).
        Parameters:
        type - A type.
        Returns:
        Whether the type of the object returned by createSnapshotTestFor(Method) is compatible to the given type.
      • createSnapshotTestFor

        public SnapshotDsl.Snapshot createSnapshotTestFor​(Method testMethod)
        Creates a Snapshot object that can be injected into a test method as starting point of the snapshot DSL.

        This method changes the state of this context object. A new Snapshot can only be created, when the current one has been retrieved and cleared using finalizeSnapshotTest().

        Parameters:
        testMethod - The test method.
        Returns:
        A Snapshot instance.
        See Also:
        finalizeSnapshotTest()
      • finalizeSnapshotTest

        public void finalizeSnapshotTest()
                                  throws Exception
        Finalizes the current test by clearing this context and executing its remaining assertions.
        Throws:
        Exception - If late assertions of the test fail.
        See Also:
        createSnapshotTestFor(Method)
      • recordFailedOrSkippedTest

        public void recordFailedOrSkippedTest​(Method testMethod)
        Records a failed or skipped test within the currently executed test class. Knowing which tests did not complete successfully is crucial for implementing orphaned snapshot detection.
        Parameters:
        testMethod - Test method that failed or has been skipped.
      • recordSnapshotTestResult

        public void recordSnapshotTestResult​(SnapshotTestResult result)
        Records the results from all snapshot assertions within a single test method.
        Parameters:
        result - A snapshot test result of a single snapshot assertion.
      • detectOrCleanupOrphanedSnapshots

        public Collection<Path> detectOrCleanupOrphanedSnapshots()
        Uses the collected context information to detect and optionally also clean up orphaned snapshot files.
        Returns:
        The detected orphans.