SetupFixture 不允许在 Resharper 中进行分组测试运行
SetupFixture does not allow grouped test runs in Resharper
我创建了一个带有 SetupFixture
属性的 class,以便根据我的集成测试程序集的需要进行一次性设置。
[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 单元测试会话 window 的分组设置为:项目和命名空间。但是,如果我使用此实例 class,Resharpers 单元测试会话会显示:
Ignored: Test should be run explicitly
甚至尝试 运行使用 MsTest 进行这些测试 运行ner:
Result Message: IntegrationTestsBase is an abstract class.
我试图将此 class 包装到命名空间,但没有任何改变。如果我 运行 一个接一个地进行单独测试,它会 运行ned,但是我不能 运行 它们都来自 GUI。
如何解决此问题才能运行 此程序集中包含的所有测试?
使用 NUnit 2.6.4、Resharper 2015.2 和 VS2015 更新 1.
您的测试class 不需要是静态的,因为它会被测试框架实例化,而静态 classes 通常无法实例化。
最快的解决方法是从 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
中的 class 不是孤立的到一个单一的测试。这是您应该注意或补偿的事情。
我创建了一个带有 SetupFixture
属性的 class,以便根据我的集成测试程序集的需要进行一次性设置。
[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 单元测试会话 window 的分组设置为:项目和命名空间。但是,如果我使用此实例 class,Resharpers 单元测试会话会显示:
Ignored: Test should be run explicitly
甚至尝试 运行使用 MsTest 进行这些测试 运行ner:
Result Message: IntegrationTestsBase is an abstract class.
我试图将此 class 包装到命名空间,但没有任何改变。如果我 运行 一个接一个地进行单独测试,它会 运行ned,但是我不能 运行 它们都来自 GUI。
如何解决此问题才能运行 此程序集中包含的所有测试?
使用 NUnit 2.6.4、Resharper 2015.2 和 VS2015 更新 1.
您的测试class 不需要是静态的,因为它会被测试框架实例化,而静态 classes 通常无法实例化。
最快的解决方法是从 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
中的 class 不是孤立的到一个单一的测试。这是您应该注意或补偿的事情。