-
@API(status=EXPERIMENTAL, since="1.1.0") public interface SnapshotNamingStrategy interface for dynamically determining snapshot names. By default, the snapshot name is made up of the test's method name and a serial number representing the count of snapshot assertions within this test method.An instance of this strategy can be passed to the DSL to customize the snapshot naming like this:
snapshot.namedAccordingTo(MyCustomNamingScheme.getInstance()).assertThat(...)...
Customizing the naming strategy is especially needed for paramterized tests, as automatic naming would choose the same snapshot name for each execution.
- Since:
- 1.1.0
- Author:
- Simon Taddiken
- See Also:
SnapshotDsl.ChooseName
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static SnapshotNamingconstant(String snapshotName)Creates a naming strategy which always returns the given constant string.static SnapshotNamingdefaultNaming()The default naming strategy which simply concatenates method name + counter.StringdetermineSnapshotName(Method testMethod, int counter)Determines the name of the snapshot being taken.static SnapshotNamingwithParameters(Object parameter1, Object... furtherParameters)Creates a naming strategy similar to the default naming strategy.
-
-
-
Method Detail
-
defaultNaming
static SnapshotNaming defaultNaming()
The default naming strategy which simply concatenates method name + counter.- Returns:
- The default naming strategy.
-
constant
static SnapshotNaming constant(String snapshotName)
Creates a naming strategy which always returns the given constant string.- Parameters:
snapshotName- The name of the snapshot.- Returns:
- Naming strategy which always returns the same name.
-
withParameters
static SnapshotNaming withParameters(Object parameter1, Object... furtherParameters)
Creates a naming strategy similar to the default naming strategy. Besides the counter, this strategy also concatenates the toString representation of various parameter objects to the snapshot name.Using this strategy is useful when using snapshot tests in combination with parameterized tests. This allows to match snapshots to an explicit set of actual parameters with which a test has been executed.
- Parameters:
parameter1- The first parameter.furtherParameters- Optional further parameters.- Returns:
- The naming strategy.
-
determineSnapshotName
String determineSnapshotName(Method testMethod, int counter)
Determines the name of the snapshot being taken. Note that the name will be used as file name for the snapshot file, so all restrictions apply that apply to your OS's file naming.Note that the result must be deterministic, otherwise the framework will not be able to match a previously persisted snapshot with a currently executed snapshot assertion.
- Parameters:
testMethod- The test method.counter- Serial number of snapshot assertions within that test method (0 based).- Returns:
- The name of the snapshot.
-
-