resharper单元测试继承 [英] resharper unit test inheritance

查看:22
本文介绍了resharper单元测试继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有在 Resharper 中进行单元测试 heiarchies 的策略?

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

我通常同时使用 TestDriven.Net 和 Resharper 的测试运行器,以及 NUnit 测试.TestDriven 在所有方面都很棒,但很快就可以从批量运行(可能是数千个)中找到一个糟糕的测试,这就是 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.

我通常使用带有覆盖测试用例的抽象基类(如下面的代码)的模式来获取正确的子类,这在 TestDriven 中效果很好,但 Resharper 只是忽略了它们!我原以为从 v5.0 开始,Resharper 使用的是 NUnit 的代码库,这意味着这应该可以工作,但没有.

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.

干杯,
贝瑞尔

[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# 做同样的事情.

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

我刚刚注意到 R#(我在 NUnit 2.6 中使用 5.1)如果一个类中有 Tests,它会将类标记为测试装置,无论是子类还是基类由 TestFixture 赋予.所以这可能无法解决您的问题.

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.

这篇关于resharper单元测试继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆