How to fix invalid ReSharper view of test names?

Viewed 154

Im using NUnit (3.8.1) with Resharper (2018.2.3) like this:

    private static IEnumerable<TestCaseData> GetTests()
    {
        yield return T("foo.bA..r@gmail.com", "foobar@gmail.com");
        yield return T("foo.bA..r@example.com", "foo.ba..r@example.com");
        yield return T("user.name+tag+sorting@example.com", "user.name@example.com");
        yield return T("admin@mailserver1", "admin@mailserver1");
        yield return T("aaaafoo.bA..r@gmail.com", "aaafoobar@gmail.com");
    }

    private static TestCaseData T(string input, string output)
    {
        return new TestCaseData(input, output)
               {
                   TestName = string.Format("'{0}' => '{1}'", input, output)
               };
    }

    [Test]
    [TestCaseSource(nameof(GetTests))]
    public void Normalize(string input, string output)
    {
        //some test here
    }

But when I run my tests, in Resharper window, I see my names cropped by some mystical logic:

invalid resharper test view

What is causing my names to become like this? How to solve it?

1 Answers

Looks like ReSharper is having issues with dots in test case names when it's running NUnit parameterized tests: it simply discards whatever precedes a dot.

There's no such problem with ReSharper running xUnit theories, for example, nor does NUnit's console runner seem to return anything weird that would seem to have an effect on ReSharper behavior.

What you can do to work around this issue is provide a descriptive name for each test case using the SetName() method, like this:

 private static IEnumerable<TestCaseData> GetTests()
    {
        yield return new TestCaseData("foo.bA..r@gmail.com", "foobar@gmail.com").SetName("GMail: dots removed, casing normalized to lower (1)");
        yield return new TestCaseData("foo.bA..r@example.com", "foo.ba..r@example.com").SetName("Example domain: dots intact, casing normalized to lower");
        yield return new TestCaseData("user.name+tag+sorting@example.com", "user.name@example.com").SetName("Example domain: local part stripped from + and everything that follows");
        yield return new TestCaseData("admin@mailserver1", "admin@mailserver1").SetName("Whatever you're checking here");
        yield return new TestCaseData("aaaafoo.bA..r@gmail.com", "aaafoobar@gmail.com").SetName("GMail: dots removed, casing normalized to lower (2)");
    }

As long as you're not using dots in the names, you should be fine:

enter image description here

Related