有没有人有在 Resharper 中对层次结构进行单元测试的策略?
我通常同时使用 TestDriven.Net 和 Resharper 的测试运行程序,进行 NUnit 测试。 TestDriven 对所有事情都很棒,但可以快速从批处理运行(可能有数千个)中找出错误的测试,这就是 Resharper 的运行程序的用武之地。
我通常使用一种模式,其中覆盖了测试用例的抽象基类(如下面的代码)以获得正确的子类,这在 TestDriven 中工作得很好,但 Resharper 只是忽略它们!我曾认为从 v5.0 开始,Resharper 正在使用 NUnit 的代码库,这意味着这应该可以工作,但事实并非如此。
干杯,
贝瑞尔
[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));
}
}
最佳答案
使您的抽象类成为 TestFixture
。我用 R# 做同样的事情。
编辑:我刚刚注意到 R#(我在 NUnit 2.6 中使用 5.1)将标记一个类作为测试夹具,如果它有 Test
,不 pipe 类或基类具有 TestFixture
属性。所以这可能无法解决您的问题。
关于c# - resharper 单元测试继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3629926/