-
Notifications
You must be signed in to change notification settings - Fork 28
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
Snapper Nunit path resolver can fail #17
Comments
Hey @JinhongZh, Thats an interesting use case. I did a quick test using
Would it be possible for you to make an example project where this issue occurs and I can use that to figure out a solution. |
Hi @theramis , |
Hi again, I don't think there is a need to dig further in this special usage of the Snapper. Thanks for the great tool by the way :) |
Hi, I've also run in this problem. It might be related to this: |
We have a scenario where we package some of our unit tests, which use Snapper, as a nuget to be distributed and consumed.
When doing this, we see an exception thrown by the Snapper Nunit path resolver code, which tries to combine path elements, but fails since it is using StackFrame.GetFileName() which returns null. Actually, this method documents that it can return null.
The code we are referring to is in NUnitTestHelper.cs:
So, if stackFrame.GetFileName() returns null, the caller - NUnitPathResolver.ResolvePath() - tries to get its directory using Path.GetDirectoryName(), which itself will return null. The null becomes the first parameter to Path.Combine(), which throws an ArgumentNullException.
As we see it, the only reason to use StackFrame.GetFileName() is to obtain the directory of the actual unit test assembly. But this could be done instead by using the declaring type of the unit test method found, and getting its assembly. So, the change would replace:
return (method, stackFrame.GetFileName());
with
return ( method, method.DeclaringType.Assembly.Location );
...and the same for the async case. Or even put the Path.GetDirectoryName() at this level instead of the caller, since only the directory is relevant.
What do you think?
The text was updated successfully, but these errors were encountered: