resharper unit test inheritance

别说谁变了你拦得住时间么 提交于 2019-12-10 18:48:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!