Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit cannot recognise a TestCase when it contains an array

This is quite simple but annoying behaviour I am running into with NUnit:

I have some tests like this:

[Test] [TestCase( 1, 2, "hello" )] [TestCase( 3, 5, "goodbye" )] public void MyClass_MyMethod( int a, int b, string c ) {     Assert.IsTrue( a < b ); } 

This works fine and in the ReSharper NUnit pane I can see each TestCase getting its own response in the result.

I have a second TestCase that looks like this:

[Test] [TestCase( 1, 2, new long[] { 100, 200 })] [TestCase( 5, 3, new long[] { 300, 500 })] public void MyClass_MyOtherMethod( long a, long b, long[] bunchOfNumbers ) {    Assert.IsTrue( a < b ); } 

When I run it I see this:

One or more child tests had errors Exception doesn't have a stacktrace

public void MyClass_MyOtherMethod(5,3,System.Int64[]) failed

The difference being that with my other tests it draws out each TestCase as a separate checkbox on the test list, whereas this one does not get shown and I have no detail until I run it in a debugger as to what went wrong and where. I am a little concerned about how this test will behave on the build machine. Does anyone have any idea what is going on and why?

like image 263
glenatron Avatar asked Jul 29 '13 13:07

glenatron


1 Answers

Following on from this bug at JetBrains it looks as though the solution here is to use the TestName attribute on your different cases:

[Test] [TestCase( 1, 2, new long[] { 100, 200 }, TestName="Test 1" )] [TestCase( 5, 3, new long[] { 300, 500 }, TestName="Test 2" )] public void MyClass_MyOtherMethod( long a, long b, long[] bunchOfNumbers ) {    Assert.IsTrue( a < b ); } 

Everything now shows correctly in ReSharper if one of my tests fails.

like image 169
glenatron Avatar answered Sep 18 '22 13:09

glenatron