Package io.quarkus.devtools.testing
Class SnapshotTesting
- java.lang.Object
-
- io.quarkus.devtools.testing.SnapshotTesting
-
public class SnapshotTesting extends Object
Test file content and directory tree to make sure they are valid by comparing them to their snapshots. The snapshots files can easily be updated when necessary and reviewed to confirm they are consistent with the changes.
The snapshots files will be created/updated using-Dsnapor-Dupdate-snapshots
Snapshots are created inSNAPSHOTS_DIR
-
-
Field Summary
Fields Modifier and Type Field Description static PathSNAPSHOTS_DIRstatic StringUPDATE_SNAPSHOTS_PROPERTYstatic StringUPDATE_SNAPSHOTS_PROPERTY_SHORTCUT
-
Constructor Summary
Constructors Constructor Description SnapshotTesting()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.assertj.core.api.ListAssert<String>assertThatDirectoryTreeMatchSnapshots(String snapshotDirName, Path dir)Test directory tree to make sure it is valid by comparing it to a snapshot.static org.assertj.core.api.ListAssert<String>assertThatDirectoryTreeMatchSnapshots(org.junit.jupiter.api.TestInfo testInfo, Path dir)Test directory tree to make sure it is valid by comparing it to a snapshot.static org.assertj.core.api.AbstractPathAssert<?>assertThatMatchSnapshot(Path fileToCheck, String snapshotIdentifier)Test file content to make sure it is valid by comparing it to a snapshot.static org.assertj.core.api.AbstractPathAssert<?>assertThatMatchSnapshot(org.junit.jupiter.api.TestInfo testInfo, Path parentDir, String fileRelativePath)Test file content to make sure it is valid by comparing it to its snapshots.static Consumer<Path>checkContains(String s)To use withAbstractPathAssertin order to check the file content contains a specific string.static Consumer<Path>checkMatches(String regex)static Consumer<Path>checkNotContains(String s)static voiddeleteTestDirectory(File file)static StringgetSnapshotDirName(org.junit.jupiter.api.TestInfo testInfo)static io.quarkus.paths.PathTreegetSnapshotsBaseTree()static StringgetTextContent(Path file)static StringnormalizePathAsName(String fileRelativePath)static <T> TwithSnapshotsDir(String relativePath, Function<Path,T> function)
-
-
-
Field Detail
-
SNAPSHOTS_DIR
public static final Path SNAPSHOTS_DIR
-
UPDATE_SNAPSHOTS_PROPERTY
public static final String UPDATE_SNAPSHOTS_PROPERTY
- See Also:
- Constant Field Values
-
UPDATE_SNAPSHOTS_PROPERTY_SHORTCUT
public static final String UPDATE_SNAPSHOTS_PROPERTY_SHORTCUT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSnapshotsBaseTree
public static io.quarkus.paths.PathTree getSnapshotsBaseTree()
-
withSnapshotsDir
public static <T> T withSnapshotsDir(String relativePath, Function<Path,T> function)
-
assertThatMatchSnapshot
public static org.assertj.core.api.AbstractPathAssert<?> assertThatMatchSnapshot(org.junit.jupiter.api.TestInfo testInfo, Path parentDir, String fileRelativePath) throws ThrowableTest file content to make sure it is valid by comparing it to its snapshots.
The snapshot file can easily be updated when necessary and reviewed to confirm it is consistent with the changes.
The snapshot file will be created/updated using-Dsnapor-Dupdate-snapshots
Even if the content is checked as a whole, it's always better to also manually check that specific content snippets contains what's expected
example:assertThatMatchSnapshot(testInfo, projectDir, "src/main/java/org/acme/GreetingResource.java") .satisfies(checkContains("@Path(\"/hello\")"))- Parameters:
testInfo- theTestInfofrom the parameter (used to get the current test class & method to compute the snapshot location)parentDir- the parent directory containing the generated files for this test (makes it nicer when checking multiple snapshots)fileRelativePath- the relative path from the directory (used to name the snapshot)- Returns:
- an
AbstractPathAssertgiving a direct way to check specific content snippets contains what's expected - Throws:
Throwable
-
assertThatMatchSnapshot
public static org.assertj.core.api.AbstractPathAssert<?> assertThatMatchSnapshot(Path fileToCheck, String snapshotIdentifier) throws Throwable
Test file content to make sure it is valid by comparing it to a snapshot.
The snapshot file can easily be updated when necessary and reviewed to confirm it is consistent with the changes.
The snapshot file will be created/updated using-Dsnapor-Dupdate-snapshots
Even if the content is checked as a whole, it's always better to also manually check that specific content snippets contains what's expected usingcheckContains(String)orcheckMatches(String)- Parameters:
fileToCheck- thePathof the file to checksnapshotIdentifier- the snapshotIdentifier of the snapshot (used as a relative path from theSNAPSHOTS_DIR- Returns:
- an
AbstractPathAssertgiving a direct way to check specific content snippets contains what's expected - Throws:
Throwable
-
assertThatDirectoryTreeMatchSnapshots
public static org.assertj.core.api.ListAssert<String> assertThatDirectoryTreeMatchSnapshots(org.junit.jupiter.api.TestInfo testInfo, Path dir) throws Throwable
Test directory tree to make sure it is valid by comparing it to a snapshot.
The snapshot file can easily be updated when necessary and reviewed to confirm it is consistent with the changes.
The snapshot file will be created/updated using-Dsnapor-Dupdate-snapshots
-
assertThatDirectoryTreeMatchSnapshots
public static org.assertj.core.api.ListAssert<String> assertThatDirectoryTreeMatchSnapshots(String snapshotDirName, Path dir) throws Throwable
Test directory tree to make sure it is valid by comparing it to a snapshot.
The snapshot file can easily be updated when necessary and reviewed to confirm it is consistent with the changes.
The snapshot file will be created/updated using-Dsnapor-Dupdate-snapshots
-
deleteTestDirectory
public static void deleteTestDirectory(File file) throws IOException
- Throws:
IOException
-
checkContains
public static Consumer<Path> checkContains(String s)
To use withAbstractPathAssertin order to check the file content contains a specific string.- Parameters:
s- the string which should be in the file content- Returns:
- a
Consumerto use withAbstractPathAssert#satisfies(Consumer)
-
getSnapshotDirName
public static String getSnapshotDirName(org.junit.jupiter.api.TestInfo testInfo)
-
-