Convert ASP.NET tests to use Snapshot Testing with VerifyTests/Verify#1454
Conversation
d310573 to
af90959
Compare
|
|
||
| // Overriding the type name here as we have multiple test classes in the file | ||
| // Ensures that we get nice file nesting in Solution Explorer | ||
| await Verifier.Verify(spans, settings) |
There was a problem hiding this comment.
Can we also set up Verify to place all snapshots in its own directory? I'm thinking something like /test/snapshots/<ProjectName>/**/verified.txt
There was a problem hiding this comment.
Well, we could yes. And for this example, that might make sense because there are so many variations, but in general I think the "default" behaviour is preferable. Having the snapshots stored "with" the test itself makes it easier to manually check them and for referring back and forth I think. We shouldn't have to do all this customisation in most cases.
I'm open to what people think though - it looks messier in file browsers, but in VS/Rider, having the snapshots folded under your test class is preferable I think, as you can easily jump to individual snapshots, but they're hidden by default:
| } | ||
|
|
||
| public static TheoryData<string, int> Data() => new() |
There was a problem hiding this comment.
This is so nice, we just need to specify the inputs and ensure the output is expected 😍
zacharycmontoya
left a comment
There was a problem hiding this comment.
LGTM. Let's verify all the things!
lucaspimentel
left a comment
There was a problem hiding this comment.
Big step forward for our testing suite, thanks! Left a couple of non-blocking comments.
|
|
||
| public AspNetWebApi2Tests(IisFixture iisFixture, ITestOutputHelper output, bool enableCallTarget, bool classicMode) | ||
| public AspNetWebApi2Tests(IisFixture iisFixture, ITestOutputHelper output, bool enableCallTarget, bool classicMode, bool enableFeatureFlag) |
There was a problem hiding this comment.
Consider renaming parameter enableFeatureFlag to something more obvious (which feature flag?). Something like enableRouteTemplateResourceNames (but shorter?). Thanks!
| + (enableCallTarget ? ".CallSite" : ".CallTarget") | ||
| + (classicMode ? ".Classic" : ".Integrated") | ||
| + (enableFeatureFlag ? ".NoFF" : ".WithFF") | ||
| + (RuntimeInformation.ProcessArchitecture == Architecture.X64 ? ".X64" : ".X86"); // assume that arm is the same |
There was a problem hiding this comment.
Should we include ARM support now so we don't have to come back and fix later?
https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture
There was a problem hiding this comment.
I'm in two minds. Will the call stack be different on Arm? Maybe not? Might not be necessary? I'm inclined to punt until we do run this on ARM (Windows Arm, I guess it's just a matter of time?)
These should never be checked in (in contrast to *.verified.* files
Json.NET update required as Verify depends on 13.0.1
Lets us use C# 9 Module Initializers on < .NET 5
We may need to add additional scrubbers etc. In addition to the built-in scrubbers, I'm - Excluding the variable duration/start fields - Fixing localhost ports to all be :0000 - Fixing the _dd.tracer_kr: 1.0 Also adds helper for fetching the web spans (without asserting), and for sanitising paths for use in filenames
The stack traces are different depending on architecture. There's a PR in to Verify to support this OOTB: VerifyTests/Verify#367

This initial PoC creates some helpers for verifying
MockTracerAgent.Spans and converts our existing ASP.NET integration tests to use snapshot testing.Challenges:
Needed to write a custom scrubber for token-replacement of IDs. This is pretty crude atm but it works. May be enabled OOTB in future Verify versionsDone in Scrub numeric ids VerifyTests/Verify#351 and Add support for scrubbing nullable numeric IDs VerifyTests/Verify#352!/in them. Solved by stripping the/.Wins:
Remaining questions:
How stable are these spans across platforms?well integration tests work, so there we go!Need to make the environments deterministic - just noticed my system levelAdded explicit setting ofDD_ENV=andrewhas made its way into the span!DD_ENVfor sample projects in 5c93c35. Can be overwritten, but should ensure consistency in other environments.There appears to be an issue with the solution path scrubbing, which is causing the current failures in the integration tests pipeline. The attributes don't appear to be embedded in the integration test project for some reason. This is probably something to do with our convoluted CI build process (as it works in VS) but I'm not sure why...🤞 Fixed in de6965c, it's because$(SolutionDir)isn't set when callingdotnet buildon a project as opposed to the solution.