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 java.lang.ObjectContext object that pertains to the execution of a whole test class which is annotated withEnableSnapshotTests.In order to initiate the run of a test class which uses snapshot assertions, you need to meet two requirements:
- You need to obtain a
SnapshotConfigurationinstance from the resp. test class viaSnapshotConfiguration.defaultConfigurationFor(Class). You can then create aSnapshotTestContextinstance from that configuration. - You need to call the lifecycle methods of the context object.
finalizeSnapshotTest()after a test method. However, in order to support full orphan detection capabilities, you need to register both all ignored tests and all failed tests of the current test execution.- Since:
- 1.1.0
- You need to obtain a
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SnapshotcreateSnapshotTestFor(java.lang.reflect.Method testMethod)Creates a Snapshot object that can be injected into a test method as starting point of the snapshot DSL.java.util.Collection<java.nio.file.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 SnapshotTestContextforConfiguration(SnapshotConfiguration snapshotConfiguration, TestFrameworkSupport testFrameworkSupport)static SnapshotTestContextforTestClass(java.lang.Class<?> testClass, TestFrameworkSupport testFrameworkSupport)Deprecated.booleanisSnapshotParameter(java.lang.Class<?> type)Determines whether the parameters with the given type are eligible for injecting the object that is created bycreateSnapshotTestFor(Method).voidrecordFailedOrSkippedTest(java.lang.reflect.Method testMethod)Records a failed or skipped test within the currently executed test class.SnapshotConfigurationsnapshotConfiguration()Returns theSnapshotConfiguration.TestFrameworkSupporttestFrameworkSupport()Returns the TestFrameworkSupport that encapsulates test framework specific behavior.java.lang.StringtoString()
-
-
-
Method Detail
-
forTestClass
@Deprecated(since="1.7.0") public static SnapshotTestContext forTestClass(java.lang.Class<?> testClass, TestFrameworkSupport testFrameworkSupport)
Deprecated.
-
forConfiguration
public static SnapshotTestContext forConfiguration(SnapshotConfiguration snapshotConfiguration, TestFrameworkSupport testFrameworkSupport)
-
snapshotConfiguration
@API(status=INTERNAL, since="1.9.0") public SnapshotConfiguration snapshotConfiguration()Returns theSnapshotConfiguration.- Returns:
- The configuration.
- Since:
- 1.9.0
-
testFrameworkSupport
@API(status=INTERNAL, since="1.10.0") public TestFrameworkSupport testFrameworkSupport()Returns the TestFrameworkSupport that encapsulates test framework specific behavior.- Returns:
- Thes
TestFrameworkSupport. - Since:
- 1.10.0
-
isSnapshotParameter
public boolean isSnapshotParameter(java.lang.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 Snapshot createSnapshotTestFor(java.lang.reflect.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 java.lang.ExceptionFinalizes the current test by clearing this context and executing its remaining assertions.- Throws:
java.lang.Exception- If late assertions of the test fail.- See Also:
createSnapshotTestFor(Method)
-
recordFailedOrSkippedTest
public void recordFailedOrSkippedTest(java.lang.reflect.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.
-
detectOrCleanupOrphanedSnapshots
public java.util.Collection<java.nio.file.Path> detectOrCleanupOrphanedSnapshots()
Uses the collected context information to detect and optionally also clean up orphaned snapshot files.- Returns:
- The detected orphans.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-