2017-01-26 12 views
0

我haved创建的类与SetupFixture属性根据需要为我的集成测试组件具有一次性设置。SetupFixture不允许分组测试运行在ReSharper的

[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单元测试会话窗口的分组设置为:Projects和Namespaces。但是,如果我用这个实例类,Resharpers单元测试会话说:

忽略:测试应该明确运行

即使试图运行这些测试与MSTest的亚军:

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

我试图将这个类封装到一个名称空间,但没有任何更改。如果我逐个运行单个测试,它会运行,但是我无法从GUI运行它们。

我怎样才能解决这个问题,以便能够运行所有测试包括在这个大会?

使用NUnit 2.6.4,ReSharper的2015.2和VS2015更新1.

回答

1

您TestClass中并不需要,因为它得到由Testframework实例和静态类通常不能被实例化是静态的。

最快的解决方法是删除static关键字,除了从您的Kernel财产。

[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类不是孤立的单个测试。你应该知道或补偿哪件事。

相关问题