简体   繁体   English

NUnit测试用例不是从继承的类运行

[英]NUnit test cases not run from inherited class

I have a base test class containing some test cases and some ordinary tests: 我有一个包含一些测试用例和一些普通测试的基本测试类:

[TestFixture]
public abstract class TestBase
{
  [TestCase(1)]
  [TestCase(2)]
  [TestCase(3)]
  public void TestA(int value)
  {
    // Perform test
  }

  [Test]
  public void TestB()
  {
    // Perform test
  }
}

These tests are run from child classes which set up the environment in different ways. 这些测试从子类运行,这些子类以不同的方式设置环境。 The child classes only contains setup methods, no tests. 子类仅包含设置方法,不包含测试。

[TestFixture]
public class LocalDatabaseTest : TestBase
{
  [SetUp]
  public void SetUp()
  {
    // Set up environment to use local db
  }
}

I'm using ReSharper 6.1.1000.82 to run all tests in LocalDatabaseTest, but only the ordinary tests are run. 我正在使用ReSharper 6.1.1000.82在LocalDatabaseTest中运行所有测试,但仅运行普通测试。 The tests using TestCase does not get any result. 使用TestCase的测试没有任何结果。 If I select Run All on TestA in the TestBase class, all test cases are run (including the other child classes). 如果我在TestBase类中选择在TestA上运行全部,则将运行所有测试用例(包括其他子类)。 I'm using NUnit 2.6.2.12296. 我正在使用NUnit 2.6.2.12296。 Any ideas on what I've done wrong? 关于我做错了什么的任何想法?

You've done nothing wrong. 你没做错任何事。

If you open your test dll via NUnit test runner you will see all test are running successfully. 如果您通过NUnit测试运行程序打开测试dll,您将看到所有测试都成功运行。
(I just verified your code with NUnit 2.6.2). (我刚刚使用NUnit 2.6.2验证了您的代码)。

Regarding the reason of ignoring parameterized tests on Resharper: It seems there is some issue with Resharper test runner which causes such behavior. 关于忽略Resharper上的参数化测试的原因:Resharper测试运行器似乎存在导致此类行为的问题。
So, my suggestion is to use NUnit to run parameterized tests. 因此,我的建议是使用NUnit运行参数化测试。

Btw, Resharper 7 has better support NUnit parameterized tests. 顺便说一句,Resharper 7更好地支持NUnit参数化测试。 And probably this issue won't appear in the latest Resharper version. 可能这个问题不会出现在最新的Resharper版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM