1

I have an xUnit project that has run all tests flawlessly until now.

I added two new test methods and now, suddenly, no tests can run because an exception is thrown:

System.Collections.Generic.KeyNotFoundException: Unable to find UniqueTest VSTestAdapter

Followed by a path to one of my test method, but sometimes when I, still, try to run all tests the method after the exception changes.

The kind of the exception leads me to think maybe the following code is related to the problem, but all tests ran fine after I wrote it, the problem appeared after I wrote two quite ordinary tests and commenting them does nothing.

The suspect code:

    public static IEnumerable<object[]> TestData
    {
        get
        {
            return new[]
            {
                new object[] { "zrgrgffwf", new string[] { "sf", "age", "fe"} },
                new object[] { "gfsefsefse", new List<string>() { "fef", "awr", "hrg" } },
                new object[] { "shgfeswff", new HashSet<string>() { "shsg", "wde", "kiuik" } },
                new object[] { "pajfoehgsd", new Queue<string>(new string[] { "okd", "rnop", "rng" }) }
            };
        }
    }

As I said, after adding that and using it in a MemberData attribute property everything ran fine several times. The problem appeared after I wrote this:

    [Theory]
    [InlineData("sample text", "lolwut", "test")]
    [InlineData("other sample text", "yup", "ahha")]
    [InlineData("yadda", "-", "yadda.")]
    [InlineData("et", "cete", "ra")]
    public void Method_Test(string testString, string testCase, string expected)
    {
        string actual = testedMethod(testCase);

        Assert.Equal(expected, actual);
    }

Additional note: I had the same exception happen before once after writing that property code, when trying to "Run all" tests in "Release" configuration. But just clicking "Run all tests" again and/or switching to "Debug" seemed to fix it - all tests ran. Now I made sure to be in "Debug" but no matter how many times I click "Run all tests" the only thing that sometimes changes is, like I said, the method cited after the exception.

J. Doe
  • 99
  • 1
  • 6
  • I don't have an answer, but I did notice this very similar issue in the xUnit GitHub repo: https://github.com/nunit/nunit3-vs-adapter/issues/685. Sounds like the bug might be in the test runner rather than in your code. – xander Jan 27 '20 at 03:10

1 Answers1

0

From the link @xander posted I saw that installing the nUnit VS adapter could fix the issue, even if I am using xUnit.

Welp, it did it for me.
While in the Test Explorer I have an additional test project show up (which is my own test project just with only the first "InlineData" taken as arguments) my xUnit tests now run.

J. Doe
  • 99
  • 1
  • 6