4

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

I have one test like this:

   static string[] EvenStr = new string[] { "1", "2", "3", "4" };

   [Test, TestCaseSource("EvenStr")]
   public void TestMethod(string num)
   {
      Assert.IsTrue( 1 == 1 );
   }

When I run it I see this:

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

    test case source could not be found

I use NUnit 3.10.1 and .net 4.5

Does anyone have any idea what is going on and why?

yousef
  • 41
  • 1
  • 2
  • 5
  • Is the array defined in the same file as the test? try `TestCaseSource(nameof(EvenStr))`, it might give you more information. – Guy Nov 05 '18 at 09:39
  • yes,it is in the same file. – yousef Nov 05 '18 at 09:41
  • The code is ok in my computer. Maybe you have a problem in another test? – Guy Nov 05 '18 at 09:44
  • Thank you very much, but that also has the same problem TestCaseSource(nameof(EvenStr)) @Guy – yousef Nov 05 '18 at 09:45
  • The use of `nameof(EvenStr)` was to see if you have any errors pop-up on this line. If not, my guess is the problem is in another test. You should always use `nameof(EvenStr)`, it will give you errors in compile time if the source is not recognized. – Guy Nov 05 '18 at 09:47
  • Because there are many different runners for NUnit tests, some of them from third parties, it's advisable that you always report how you are running tests when asking about a problem. For example, under nunit3-console, under the VS test adapter, using resharper, etc. – Charlie Nov 06 '18 at 11:42
  • @Charlie. You are right, I forgot to say I run NUnit under the Resharper. – yousef Nov 06 '18 at 17:41
  • To figure out if the problem is NUnit or Resharper, you could run your example test with either nunit3-console or nunitlite. – Charlie Nov 07 '18 at 20:45
  • Works for me using: NUnit 3.10.1 and .NET Framework 4.8 using the NUnit 3 Test Adapter with VisualStudio 2017 Community – Lorenzo Solano Martinez Jul 29 '19 at 15:30
  • 1
    I copied this test to another solution and everything worked correctly, and after removed this test from that solution another tests worked correctly, it was amazing for me but it is't the first time that Visual Studio surprised me. – yousef Aug 03 '19 at 05:41
  • 4
    For anyone arriving at this question through Google - in my case, the error was because my equivalent to `EvenStr` was in a different class and I had left it `private` when it should have been `public`. – Luna Sep 17 '19 at 17:08

0 Answers0