You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TestName in TestCase attribute not validated to be not empty #3038
The usage of NUnit in our project in rather advanced. We use many publicly available features as well as some undocumented ones ;)
And we have a homebrew integration of NUnit and ReportPortal (by EPAM) which attaches itself to NUnit engine like a parasite, for the information about currently running tests to be transfered to RP in real time (not after the test run is completed) even when running tests in debug mode from VS. We use the information supplied by NUnit such as test names, descriptions, categories, ignore reasons etc to make test reports as easy to read as possible.
Several days ago reports at RP started indicating integration problems which occur very rarely. I took a deeper look and found errors at RP logs saying that test name constraint "not empty" fails test report creation. Further research pointed at a new test in our project which had its attributes defined like this:
[Test][TestCase(TestName="")][Category("DB")]
We use this workaround with TestCase for having a human-readable test name supplied by NUnit instead of coding a custom attribute. And in many cases we use TestCase attribute for its intended purpose as well.
So obviously one programmer forgot to type in the value for TestName. The integration code was looking at ITest.Name property which appeared to be an empty string. And an empty string in its turn appeared to be unacceptable as a test name for RP.
If you run this test with Resharper, it displays a test icon with nothing next to it (no name), which means Resharper relies on the same NUnit functionality.
And this is it's section from TestResult.xml (removed newlines of CDATA nodes to simplify reading):
<test-caseid="0-1001"name=""fullname="NUnitEmptyTestNameTest.Class1."methodname="Test1"classname="NUnitEmptyTestNameTest.Class1"runstate="Runnable"seed="1994871090"result="Failed"start-time="2018-10-02 12:35:30Z"end-time="2018-10-02 12:35:31Z"duration="0.103357"asserts="1">
<failure>
<message><![CDATA[ Expected: not null But was: null ]]></message>
<stack-trace><![CDATA[ at NUnitEmptyTestNameTest.Class1.Test1() in MY_SOLUTION_PATH\NUnitEmptyTestNameTest\Class1.cs:line 13 ]]></stack-trace>
</failure>
<assertions>
<assertionresult="Failed">
<message><![CDATA[ Expected: not null But was: null ]]></message>
<stack-trace><![CDATA[ at NUnitEmptyTestNameTest.Class1.Test1() in MY_SOLUTION_PATH\NUnitEmptyTestNameTest\Class1.cs:line 13 ]]></stack-trace>
</assertion>
</assertions>
</test-case>
The issue is not about 3rd party products, I've described the process just to clarify the context. The issue is about Name property of the ITest and of the TestAdapter. Empty test name is anyway not normal - that's what I'm trying to tell :)
Thanks. What I was thinking of, was whether this currently causes any issue for NUnit itself, or if it's just a case of third party products which make assumptions that NUnit doesn't guarantee (e.g. Test names not being empty!) Based on the above - it seems to be the former.
That said - I can't think of any sensible use for wanting empty string test names, so think it could be sensible to add this restriction to NUnit - to avoid user error, like you've had above. What do @nunit/framework-team think?
@ChrisMaddock I've never had any deal with NUnit source code except for reading several portions of code to understand how some of the features work. I'll give it a try but first let @nunit/framework-team tell me which one of the two solutions (exception or providing a generated value) suits better.
Activity
ChrisMaddock commentedon Oct 2, 2018
Hey @sbakharev - thanks for the clear report! 🙂
Resharper and ReportPortal are both third party products in this instance. What result do you get if you run this test with the NUnit Console?
sbakharev commentedon Oct 2, 2018
@ChrisMaddock wow, what a fast reaction!
This test:
Produces this test context output:
And this is it's section from TestResult.xml (removed newlines of CDATA nodes to simplify reading):
The issue is not about 3rd party products, I've described the process just to clarify the context. The issue is about Name property of the ITest and of the TestAdapter. Empty test name is anyway not normal - that's what I'm trying to tell :)
P.S. NUnit console latest version 3.9.0
ChrisMaddock commentedon Oct 3, 2018
Thanks. What I was thinking of, was whether this currently causes any issue for NUnit itself, or if it's just a case of third party products which make assumptions that NUnit doesn't guarantee (e.g. Test names not being empty!) Based on the above - it seems to be the former.
That said - I can't think of any sensible use for wanting empty string test names, so think it could be sensible to add this restriction to NUnit - to avoid user error, like you've had above. What do @nunit/framework-team think?
jnm2 commentedon Oct 3, 2018
I think requiring a non-whitespace string is sensible.
ChrisMaddock commentedon Oct 3, 2018
Great - then let's do it. @sbakharev - is this something you'd be willing to supply a pull request for?
sbakharev commentedon Oct 4, 2018
@ChrisMaddock I've never had any deal with NUnit source code except for reading several portions of code to understand how some of the features work. I'll give it a try but first let @nunit/framework-team tell me which one of the two solutions (exception or providing a generated value) suits better.
CharliePoole commentedon Oct 4, 2018
I think that we would expect the test to be non-runnable, as in your first option.
Require non-whitespace string as test name