Interface SnapshotDsl.ChooseName

    • Method Detail

      • named

        default SnapshotDsl.ChooseActual named​(String snapshotName)
        Choose a name for the snapshot file. This overrides the default naming scheme of using method name + consecutive number. Note that, when you specify the same name twice within test cases for the same snapshot directory, snapshots will be silently overridden and tests may subsequently fail.
        Parameters:
        snapshotName - The name of the snapshot to create.
        Returns:
        Fluent API object for choosing the snapshot format. Do NOT assume it is the same object as 'this'!
      • namedAccordingTo

        @API(status=EXPERIMENTAL,
             since="1.1.0")
        SnapshotDsl.ChooseActual namedAccordingTo​(SnapshotNaming namingStrategy)
        Choose a name for the snapshot file according to the given strategy.

        The SnapshotNaming interface has some static methods with useful implementations. You can also easily implement the interface yourself.

        For example, in a parameterized test, snapshot can be named like this:

         @ParameterizedTest
         @ValueSource(strings = { "a", "b" })
         void someTest(String parameter, Snapshot snapshot) {
             snapshot.namedAccordingTo(SnapshotNaming.withParameters(parameter))
                     .assertThat(parameter)
                     .asText()
                     .matchesSnapshotText();
         }
         
        Parameters:
        namingStrategy - The naming strategy to use.
        Returns:
        Fluent API object for choosing the snapshot format. Do NOT assume it is the same object as 'this'!
        Since:
        1.1.0