Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a lightweight entrypoint with simple static assertThat method #45

Open
skuzzle opened this issue Nov 29, 2022 · 1 comment
Open

Comments

@skuzzle
Copy link
Owner

skuzzle commented Nov 29, 2022

Currently our framework is deeply integrated into the whole test execution life cycle. We rely on several information that are provided by JUnit:

  • We use the test method for determining snapshot names from SnapshotNaming strategy
  • We use the number of executed assertions within the same test method for automatic snapshot naming
  • We use the test method and the test class to check for presence of @ForceUpdateSnapshots and @DeleteOrphanedSnapshots annotations
  • We use the test class to determine the default snapshot directory.
  • We collect information about failed and skipped tests to improve orphan detection

Those are the main reasons why we currently can not offer a simple static assertThat(actual).matchesSnapshotText() API.

We could try to find heuristics to determine the currently required information.

A simple soultion would be to try to determine the surrounding test class by iterating the current call stack and to rely on manual snapshot naming. That would allow to write assertions like this:

SnapshotAssert
    .assertThat(actual)
    .named("my-snapshot")
    .as(JsonSnapshot.json)
    .matchesSnapshotStrucure();
@skuzzle
Copy link
Owner Author

skuzzle commented Dec 5, 2022

Relying on manual snapshot naming is not sufficient. The header part must contain the real name of the method, otherwise it will always be determined as orphaned by the StaticOrphanDetector. Or we need to introduce yet another header field that indicates the mismatch between the manual name and the real test method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant