views:

59

answers:

1

Has anyone got a strategy for unit testing heiarchies in Resharper?

I typically use both TestDriven.Net and Resharper's test runner, with NUnit tests. TestDriven is awesome for everything but quickly finding a bad test out of a batch run (which could be thousands), which is where Resharper's runner comes in.

I typically use a pattern with an abstract base class (like the code below) of test cases overridden to get the right subclass, which works great in TestDriven, but Resharper just ignores them! I had thought as of v5.0 Resharper was using NUnit's code base, which means this should work but it doesn't.

Cheers,
Berryl

[TestFixture]
public class AdminAccountTests : AccountTests
{
    protected override Account _GetAccount() { return new AdminAccount(_idScheme, _description); }
}

[TestFixture]
public class LeaveTimeAccountTests : AccountTests
{
    protected override Account _GetAccount() { return new LeaveTimeAccount(_idScheme, _description); }
}

public abstract class AccountTests
{
    protected abstract Account _GetAccount();

    [SetUp]
    public void SetUp()
    {
        _account = _GetAccount();
    }

    [Test]
    public void OnCreation_Blah() {
        Assert.That(_account.IdScheme, Is.EqualTo(_idScheme));
    }

}
A: 

Make your abstract class a TestFixture. I do this same thing with R#.

EDIT: I just noticed that R# (I'm using 5.1 with NUnit 2.6) will mark a class as a test fixture if it has Tests in it, regardless of whether the subclass or the base class are attributed with TestFixture. So that may not solve your problem.

arootbeer
I did try that, with no luck. Thanks for the reply tho
Berryl
@RootBeer. See Hadi's response, sounds like he is with Jet Brains, and indicates this was a problem that has been fixed in the latest R# 5.1.1 release. I also installed the latest NUnit while I was at it (2.5.7.10213). The code I posted now executes in R#. Cheers!
Berryl
Good to hear. Thanks for the check!
arootbeer