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 way to merge @SnapshotTestOptions #101

Open
skuzzle opened this issue May 3, 2023 · 1 comment
Open

Provide a way to merge @SnapshotTestOptions #101

skuzzle opened this issue May 3, 2023 · 1 comment

Comments

@skuzzle
Copy link
Owner

skuzzle commented May 3, 2023

As the amount of configurable option grows, we must provide a way to merge hierarchically used options. Otherwise it would not be easily possible to refine the used options per test case.

@SnapshotTestOptions(attribute1 = nonDefaultValue, attribute2 = nonDefaultValue, attribute3 = nonDefaultValue)
class TestClass {

    @Nested
    @SnapshotTestOptions(attribute1 = nonDefaultValue)
    class InnerTestClass {
        @Test
        @SnapshotTestOptions(attribute1 = defaultValue, attribute2 = nonDefaultValue)
        void innerTestMethod(Snapshot snapshot) {
            // actual options:
            // attribute1 = defaultValue
            // attribute2 = nonDefaultValue
            // attribute3 = nonDefaultValue
        }
    }
}

Problem here is, that we need to distinguish between implicit and explicit default values.
attribute1 on the test method has an explicit default value which is intended to override a previously configured non-default value. Whereas attribute3 has an implicit default value which is not intended to override a previously configured non-default value

To be finoished:
Merging algorithm:

  1. Traverse the hierarchy from bottom to top, starting at the testMethod
  2. Read @SnapshotTestOptions from current element. If non is present, use SnapshoTestOptions.DEFAULT_OPTIONS
  3. Read desired attribute from the obtained SnapshotTestOptions
  4. If the attribute's value is not its default value, return it immediately
  5. If the attribute's value is its default value, continue traversing the hierarchy until a non-default value is encountered
@skuzzle
Copy link
Owner Author

skuzzle commented Jan 19, 2024

After giving this some more thought I think it is best to move away from annotation based config. There is no need for these settings be evaluated statically, so we could just as well move to a programmatic options API. That would be way more flexible and composable

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

No branches or pull requests

1 participant