【问题标题】:SetupFixture does not allow grouped test runs in ResharperSetupFixture 不允许在 Resharper 中进行分组测试运行
【发布时间】:2017-01-26 10:22:50
【问题描述】:

我已经创建了一个具有SetupFixture 属性的类,以便根据我的集成测试程序集的需要进行一次性设置。

[SetUpFixture]
public static class IntegrationTestsBase
{
    public static IKernel Kernel;

    [SetUp]
    public static void RunBeforeAnyTests()
    {
        Kernel = new StandardKernel();
        if (Kernel == null)
            throw new Exception("Ninject failure on test base startup!");

        Kernel.Load(new ConfigModule());
        Kernel.Load(new RepositoryModule());
    }

    [TearDown]
    public static void RunAfterAnyTests()
    {
        Kernel.Dispose();
    }
}

Resharpers 单元测试会话窗口有一个分组设置为:项目和命名空间。但是,如果我使用这个实例类,Resharpers Unit Test Session 会说:

忽略:应显式运行测试

甚至尝试使用 MsTest 运行器运行这些测试:

结果消息:IntegrationTestsBase 是一个抽象类。

我试图将这个类包装到一个命名空间,但没有任何改变。如果我一个接一个地运行单个测试,它就会运行,但是我不能从 GUI 中运行它们。

如何解决此问题才能运行此程序集中包含的所有测试?

使用 NUnit 2.6.4、Resharper 2015.2 和 VS2015 更新 1。

【问题讨论】:

    标签: c# nunit resharper integration-testing


    【解决方案1】:

    您的 Testclass 不需要是静态的,因为它由 Testframework 实例化,而静态类通常不能被实例化。

    最快的解决方法是从您的 Kernel 属性中删除 static 关键字。

    [SetUpFixture]
    public class IntegrationTestsBase
    {
        public static IKernel Kernel;
    
        [SetUp]
        public void RunBeforeAnyTests()
        {
            Kernel = new StandardKernel();
            if (Kernel == null)
                throw new Exception("Ninject failure on test base startup!");
    
            Kernel.Load(new ConfigModule());
            Kernel.Load(new RepositoryModule());
        }
    
        [TearDown]
        public void RunAfterAnyTests()
        {
            Kernel.Dispose();
        }
    }
    

    请记住,您在 Kernel 中输入的任何内容现在都是共享的,因此如果此测试使用多个线程运行,Kernel 中的类不会被隔离到单个测试中。这是您应该注意或补偿的事情。

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多