1
Vote

Inconclusive results for inherited NUnit tests

description

I've been using AgUnit successfully with R# 8.2 and MSTest but am now looking at converting over to NUnit. I was able to get NUnit for my .NET projects and NUnitLite for my SL projects and it's mostly working. However, I have some test classes where there is an abstract base class with test methods and then a few different derivations that also have their own test methods.

When these were decorated with MSTest attributes, they show up in the R# test runner just like any other method. However, once I switched over to NUnit, they show up with the name of the base class before the method name.

I dug into this and it looks like R# does some special processing for NUnit tests that are inherited from an abstract parent class and the "ShortName" that it provides in the NUnitTestTask is actually the base class's name plus the method name. See the NUnitTestElement class which contains both a ShortName property and a ShortNameWithTypeForDerivedTest property.

The AgUnit code inside NUnitMethodTaskProvider that tells StatLight which methods to run is always assuming that the ShortName just contains the method name but for these inherited tests, it doesn't so StatLight doesn't know which tests to run and they come back as inconclusive.

I was able to fix this by changing the NUnitMethodTaskProvider.GetFulMethodName method from:
    public string GetFullMethodName(RemoteTask task)
    {
        var methodTask = GetTask(task);

        return string.Format("{0}.{1}", methodTask.TypeName, methodTask.ShortName);
    }
to:
    public string GetFullMethodName(RemoteTask task)
    {
        var methodTask = GetTask(task);
        var methodName = methodTask.ShortName.Split('.').Last();

        return string.Format("{0}.{1}", methodTask.TypeName, methodName);
    }
It would be nice if this was included in the next release of AgUnit.

comments

SDeKock wrote Nov 23, 2014 at 8:25 PM

Thank you for putting the time into fixing this issue.
It would be of great help if you can send this as a pull request on GitHub: https://github.com/sdekock/AgUnit/

I'm not sure when, or if, I will be putting out a new version of AgUnit.
Silverlight is a major red flag for new projects and ReSharper 9 support probably isn't happening unless someone else can put up the work for it (or I'm really bored ... but that's highly unlikely).