-
Notifications
You must be signed in to change notification settings - Fork 7
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
Consider using the Verify package for snapshot testing #100
Comments
I like the workflow of Verify. It cleanly separates "received" and "verified" versions of the test output. There is rich tooling integration, such as a .NET tool to accept, reject, or skip unverified ("received") changes in the test output. I also like how it prescribes changes to I also like the naming conventions of the snapshot files because they appear as child items of the test class. Some things to figure out:
|
Concern 1 is not a big deal IMO. There can be a couple strict tests about CSV serialization and the rest can be highly readable entity-based assertions. Concern 2 is not a big deal at all. In my POC this was easy and also forced me to refactor test helpers making them clean in the end. Snapshot naming based off of Concern 3 seems fine. I just Concern 4 is annoying but also not a big problem. It's easily mitigated with |
I disagree with some of the defaults in the library such as launching the diff tool automatically (annoying for many test files). Mitigated with I think the custom serialization of not-quite JSON is not right for the project. I dislike new serialization schemes so normal JSON can be used with I dislike the default Using During the migration, I will assert on the entire CSV string instead of the deserialized CSV record POCOs so I can see the snapshots haven't changed. Later, we can switch to asserting on array of CSV POCO instead of a big nasty CSV string. This will make future diffs more readable. |
Since there are dozens of snapshot files for some test classes, I think I will put all of the test files in a |
My preference is to keep snapshots as close to the class that generates them. Note that Verify helps keep this use case clean by nesting snapshots under the file that generates them |
there is the concept of Converters https://github.com/VerifyTests/Verify/blob/main/docs/converter.md |
can u point me to one of these tests, and i can possible propose an alternative that does not require DisableRequireUniquePrefix |
if you start with a PR that adds Verify, i can help when u hit issues |
Haha, I keep going back and forth on which I like better. I think as long as there are not too many test classes or test methods in one directory then it's okay to keep the test files next to the test file. I'm just worried about a directory with 100s of files making the GitHub browser,
This makes sense. I see Verify really as a tilt towards improving dev experience over what Insights has today. The test data diff we have today is pretty much impossible to read. Like there are CSV files with serialized JSON in some of the cells. This is impossible to read even in Beyond Compare which has CSV diff. I prototyped a I don't know if I want to keep the whole CSV or not... I like the idea of having that strict verification for all tests but it does mean any PR diffs that change or add CSVs have some pieces that are opaque (the CSV string diff) and other parts that are highly readable (the serialized object diff). This is probably the best of both worlds and we just as a team need to know that some parts of PR diffs will be hard to read and to just focus on the readable parts knowing that the unreadable parts are just there for strictness. Still thinking about it. But I will definitely look into the Converter feature.
This is the existing test before introducing Verify. It asserts both the shape of some Azure Table Storage entities (intermediate state for NuGet Insights) and CSV (the final output of NuGet Insights) Lines 19 to 54 in 2c7e463
Description of the code under test: https://github.com/NuGet/Insights/blob/main/docs/drivers/PackageCertificateToCsv.md Existing test data: https://github.com/NuGet/Insights/tree/main/test/Worker.Logic.Test/TestData/PackageCertificateToCsv The CSVs are split by record type (T1, T2 -- referring to type parameters to the test suite and driver: one piece of code produces two CSVs per package it processes in this case). Each CSV type is also partitioned into buckets (
Thank you for the offer! You've already been very helpful in this thread. Here's what I have so far: #106 (draft). It has the I currently forced Verify to encode test data the same way it already is but put the snapshot files in a new place. I am focusing on the changes to C# right now not the snapshot shape. |
yeah. in that scenario i move the test and its snapshots into their own directory to keep them together |
Attempted here but ran into blockers: #106. |
I independently discovered snapshot testing and wrote hacky thing myself 😅.
https://github.com/VerifyTests/Verify - this might be better to use
The text was updated successfully, but these errors were encountered: