问题
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));
}
}
回答1:
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.
回答2:
I have the same issue with MbUnit and Gallio with resharper 5.1.3000.12. If i try to launch the test through visual studio plugin, the test is ignored. With external gallio test runner, it works fine.
JetBrains ReSharper 5.1 C# Edition Build 5.1.3000.12 on 2011-01-28T05:05:56
Plugins: 1. “Gallio Test Runner” v3.2.0.0 by Gallio Visual Studio 9.0.30729.1.
Copyright © 2003–2011 JetBrains s.r.o.. All rights reserved.
来源:https://stackoverflow.com/questions/3629926/resharper-unit-test-inheritance