-
Notifications
You must be signed in to change notification settings - Fork 735
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
Framework throws NullReferenceException if test parameter is marked with [Values(null)] #2630
Comments
You're right! Thanks for spotting that. We should be doing the same thing we do for nunit/src/NUnitFramework/framework/Attributes/TestCaseAttribute.cs Lines 52 to 55 in e914415
And we should be doing the same test: nunit/src/NUnitFramework/tests/Attributes/TestCaseAttributeTests.cs Lines 509 to 513 in e914415
This is pretty straightforward. @LeonidVasilyev, are you interested in contributing the fix? |
@jnm2 There's a little more to it, I think, although not much. Introduction of ParamAttributeTypeConversions seems to have started it. The GetData method needs a Guard statement and the call should be conditional. I'm a bit surprised that the params argument is the one selected but there's no way we can change that. |
Thanks, yes. The implementer should add a nunit/src/NUnitFramework/framework/Internal/ParamAttributeTypeConversions.cs Lines 53 to 55 in 04c6b7b
@CharliePoole Which call should be conditional? |
Ah, this one, I think: nunit/src/NUnitFramework/framework/Attributes/ValuesAttribute.cs Lines 101 to 104 in 04c6b7b
If |
I think that call points out the problem. The field I'm doubting "good first issue"on this one. Maybe @mikkelbu wants to come back to it. 😸 |
Do we even need a check? The only possible cause is if Yep, agree. |
If we fix the constructor, I agree we can avoid the check. |
Okay. To recap: We should be doing the same thing in the ValuesAttribute params constructor that we do for nunit/src/NUnitFramework/framework/Attributes/TestCaseAttribute.cs Lines 52 to 55 in e914415
And we should be doing the same test: nunit/src/NUnitFramework/tests/Attributes/TestCaseAttributeTests.cs Lines 509 to 513 in e914415
We should add a nunit/src/NUnitFramework/framework/Internal/ParamAttributeTypeConversions.cs Lines 53 to 55 in 04c6b7b
And add a test to ParamAttributeTypeConversionTests to ensure this behavior. @mikkelbu (or @LeonidVasilyev), are you interested in working on this one? |
@jnm2 Not particularly 😄, but if I have time then I could take a look at this. |
Oh, I think I mixed up the two issues. I'll do it if I have time. |
@jnm2, thank you for asking. Unfortunately, I'm currently in lack of time needed to setup all environment and study the developer documentation. Maybe I will comeback to this issue if nobody will do this earlier. |
@CharliePoole, It appears to be that C# compiler treats constructor with params array as more specific than constructor with single object parameter because every |
As part of fixing this bug, I copied many tests from TestCaseAttributeTests to ValuesAttributeTests and to my surprise there are at least two new kinds of |
I imagine this overlaps with @StanEgo's ongoing work on #2104. Maybe one to discuss, to avoid duplicating work. 🙂 |
Good, thanks for pointing that out! I'll have to rewrite the one I am editing. 😊 |
I'm using NUnit 3.9.0, NUnit Console Runner 3.7.0 and NUnit 3 Test Adapter 3.9.0 for Visual Studio Community 2017.
Exception is seems to be thrown by access to
Array.Length
property inParamAttributeTypeConversions.GetData()
.Values(null)
is resolved toValuesAttribute(params object[] args)
call. Issue can be reproduced using following code snippet:In Visual Studio test is not discovered during test project build, i.e. it doesn't appear in Test Explorer list of tests. No message is shown in Output window. NUnit Console Runner shows following error message:
You can check original use case in How to pass NULL value to ValuesAttribute of the test method? discussion on StackOverflow.
The text was updated successfully, but these errors were encountered: