Package io.quarkus.devtools.testing
Class SnapshotTesting
java.lang.Object
io.quarkus.devtools.testing.SnapshotTesting
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
Snapshots are created in
The snapshots files will be created/updated using
-Dsnap or
-Dupdate-snapshots
Snapshots are created in
SNAPSHOTS_DIR-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.To use withAbstractPathAssertin order to check the file content contains a specific string.checkMatches(String regex) static voiddeleteTestDirectory(File file) static StringgetSnapshotDirName(org.junit.jupiter.api.TestInfo testInfo) static io.quarkus.paths.PathTreestatic StringgetTextContent(Path file) static StringnormalizePathAsName(String fileRelativePath) static <T> TwithSnapshotsDir(String relativePath, Function<Path, T> function)
-
Field Details
-
SNAPSHOTS_DIR
-
UPDATE_SNAPSHOTS_PROPERTY
- See Also:
-
UPDATE_SNAPSHOTS_PROPERTY_SHORTCUT
- See Also:
-
-
Constructor Details
-
SnapshotTesting
public SnapshotTesting()
-
-
Method Details
-
getSnapshotsBaseTree
public static io.quarkus.paths.PathTree getSnapshotsBaseTree() -
withSnapshotsDir
-
assertThatMatchSnapshot
public static org.assertj.core.api.AbstractPathAssert<?> assertThatMatchSnapshot(org.junit.jupiter.api.TestInfo testInfo, Path parentDir, String fileRelativePath) throws Throwable Test 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 -
getTextContent
-
deleteTestDirectory
- Throws:
IOException
-
checkContains
To use withAbstractPathAssertin order to check the file content contains a specific string. -
checkNotContains
-
checkMatches
-
getSnapshotDirName
-
normalizePathAsName
-