Comments (13)
same as #16 but different exception.
from snapper.
Interesting.
Do you happen to have an example of a test which has this error?
I just tried to replicate it how #16 was replicated and I don't get the same error.
I get
Snapper.Exceptions.SupportedTestMethodNotFoundException : A supported test method was not found. Make sure you are using Snapper inside a supported test framework. See https://theramis.github.io/Snapper/faqs.html for more info
which is what I expected.
from snapper.
Getting this error with netcore 2.1 Xunit for some of my snapper tests in release even when decorating the method with [Fact, MethodImpl(MethodImplOptions.NoInlining)]
(but optimize false in csproj does work).
My branch that is already on netcore 3.1 doesn't have the issue so not sure how helpful this is from a debugging perspective but it's more weight to the argument to switch to [CallerMemberName] .
Message: System.ArgumentNullException : Value cannot be null. Parameter name: path1 Stack Trace: Path.Combine(String path1, String path2, String path3) SnapshotIdResolver.ResolveSnapshotId(String partialSnapshotName) Snapper.MatchSnapshot(Object snapshot, String partialSnapshotName) IntegrationApiTests.GetAssetConfigsMatchesSnapshot() --- End of stack trace from previous location where exception was thrown ---
from snapper.
Hey @WarrenFerrell,
I've been thinking about this problem lately and I think I have a nice solution.
I'm thinking of introducing the concept of passing letting a user pass in a SnapshotId
which would define the location of the snapshot.
So it would end up looking something like this. (this isn't final but just an example of how it could look)
obj.ShouldMatchSnapshot(new SnapshotId(filePath, snapshotName, childSnapshotName);
What would you think about that?
The benefits of this approach are that it could work for any test framework since there would be no reliance on trying to figure out the class/method name. It lets the user completely decide where and how they want to store their snapshots.
The biggest downside for me with using [CallerMemberName]
is that it only works if the ShouldMatchSnapshot
method is called in the same method as the test method. If for example you had an helper method which calls ShouldMatchSnapshot
and you call the helper method from the your test method. The member name would be the name of the helper method which isn't what the user would want.
from snapper.
That's a very good point about helper methods, that would actually break some of my own tests.
For SnapshotIds, I like it There should be some validation around multiple tests calling the same snapshot though. I can easily see this being done intentionally using inlinedata but I would expect one test run to require all runtime references to the same snapshot contain the same value be the same. It would probably be preferrable if the snapshot doesn't get written when there is a conflict so the original snapshot value and the value from every reference will probably need to be stored.
from snapper.
For SnapshotIds, I like it There should be some validation around multiple tests calling the same snapshot though. I can easily see this being done intentionally using inlinedata but I would expect one test run to require all runtime references to the same snapshot contain the same value be the same. It would probably be preferrable if the snapshot doesn't get written when there is a conflict so the original snapshot value and the value from every reference will probably need to be stored.
Good point about conflicts, I didn't consider that. Passing in the snapshot does introduce some problems and limitations. I'm not sure solving for conflicts is worth it though (or even possible).
For Snapper to figure out if there is a conflict, it would need to somehow scan for all places where the SnapshotId
class is being made and then figuring out is getting called by multiple tests without changing the filepath. That is super super complex and wouldn't be perfect either.
The other way would be for snapper to internally store all the snapshot ids that have been passed in during that test run, and then throw as exception if the same id was passed in twice. Unfortunately this won't be fool proof either because you can have partial test runs where not all tests are run.
The other limitation of this the snapshot id method is that in some cases the user can't use the [UpdateSnapshots]
attribute. A user would generally use this snapshot id method when Snapper can't determine the test method, which case Snapper also can't check if the test method has the attribute.
I'm now thinking I could release this as an experimental feature until I/someone has a better idea.
from snapper.
You could pass the SnapshotId via an attribute. That makes the reflective task of finding all methods using SnapshotIds vastly easier. I think it would be nice to be able to have multiple tests call the same snapshot but the initial implementation could forgo that capability as long as it doesn't restrict it from being added later.
from snapper.
You could pass the SnapshotId via an attribute. That makes the reflective task of finding all methods using SnapshotIds vastly easier. I think it would be nice to be able to have multiple tests call the same snapshot but the initial implementation could forgo that capability as long as it doesn't restrict it from being added later.
Unfortunately passing it in via attribute won't work. One of the main reasons for implementing this feature is because it's not always possible to to detect which attributes are applied onto the test method when ShouldMatchSnapshot
is called.
I'll try a bunch of different things and try release this as an experimental feature soonish. It'll have a bunch of limitations but it should solve some problems for some people.
from snapper.
I figured I would chime in to say I'm running into this same issue with our automated test builds in Azure devops. Adding the NoInlining
attribute doesn't seem to work either... Sounds like being able to hardcode the snapshot id into the test method implementation is the most guaranteed approach to get around the problem.
from snapper.
@theramis do you know why the Null exception is thrown instead of the SupportedTestMethodNotFoundException in TestMethodResolver.cs: 41 . It seems as though the the method is found but stackFrame.GetFileName is returning null. It might be nice to have an exception when this occurs to help figure out what is going on.
from snapper.
@theramis do you know why the Null exception is thrown instead of the SupportedTestMethodNotFoundException in TestMethodResolver.cs: 41 . It seems as though the the method is found but stackFrame.GetFileName is returning null. It might be nice to have an exception when this occurs to help figure out what is going on.
Interesting haven't seen that before. I imagine it can happen when the debug files are not populated enough for it to extract the filename from. The comment here https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackFrame.cs#L154-L163 suggests its extracted from the debug files.
You can try adding
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>false</Optimize>
</PropertyGroup>
to your csproj and see if that fixes the issue.
I will update Snapper to catch this exception though and throw SupportedTestMethodNotFoundException
if this use case happens.
Thanks!
from snapper.
Sorry about the late response. Yes the Optimize tags has been the only way for me to resolve that exception. Unfortunately it is extremely difficult to reliably reproduce it. Methods that did it before no longer do.
from snapper.
I've released a fix for this in 2.2.4.
from snapper.
Related Issues (20)
- Add support of self referencing loop HOT 3
- [BUG] Snapshots do not match HOT 4
- [BUG] ArgumentException: Object serialized to String. JObject instance expected. HOT 4
- [DOCUMENTATION] SupportedTestMethodNotFoundException HOT 3
- Approach to Environment.NewLine HOT 6
- Use Custom DSL instead of Inheriting NUnit.Framework.Is HOT 5
- Allow exclusion of fields HOT 2
- Create snapshot on first run if none exists HOT 1
- Add support for Specflow
- Custom update snapshot attributes HOT 2
- Allow customising the serializer settings for Snapshots HOT 2
- Add alternative snapshots for decimal values HOT 4
- Serializing non json values HOT 2
- SnapshotDoesNotExistException on Azure Pipelines ubuntu-20.04 Agent HOT 4
- Plain text serialization HOT 4
- Snapshot created with different serialization settings HOT 6
- Enable changing only the snapshot filename HOT 6
- Support NExpect HOT 9
- Support for Unity Test Framework HOT 5
- Remove support for .net 45 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snapper.