Package de.skuzzle.test.snapshots.impl
Class SnapshotTestContext
- java.lang.Object
-
- de.skuzzle.test.snapshots.impl.SnapshotTestContext
-
@API(status=INTERNAL, since="1.1.0") public final class SnapshotTestContext extends ObjectContext object that pertains to the execution of a whole test class which is annotated withEnableSnapshotTests.- Since:
- 1.1.0
- Author:
- Simon Taddiken
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SnapshotDsl.SnapshotcreateSnapshotTestFor(Method testMethod)Creates a Snapshot object that can be injected into a test method as starting point of the snapshot DSL.Collection<Path>detectOrCleanupOrphanedSnapshots()Uses the collected context information to detect and optionally also clean up orphaned snapshot files.voidfinalizeSnapshotTest()Finalizes the current test by clearing this context and executing its remaining assertions.static SnapshotTestContextforTestClass(Class<?> testClass)booleanisSnapshotParameter(Class<?> type)Determines whether the parameters with the given type are eligible for injecting the object that is created bycreateSnapshotTestFor(Method).voidrecordFailedOrSkippedTest(Method testMethod)Records a failed or skipped test within the currently executed test class.voidrecordSnapshotTestResult(SnapshotTestResult result)Records the results from all snapshot assertions within a single test method.
-
-
-
Method Detail
-
forTestClass
public static SnapshotTestContext forTestClass(Class<?> testClass)
-
isSnapshotParameter
public boolean isSnapshotParameter(Class<?> type)
Determines whether the parameters with the given type are eligible for injecting the object that is created bycreateSnapshotTestFor(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 ExceptionFinalizes 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.
-
-