Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. The tests using TestCase does not get any result. If I select Run All on TestA in the TestBase class, all test cases are run (including the other child classes). I'm using NUnit 2.6.2.12296. Any ideas on what I've done wrong?

like image 820
Anlo Avatar asked Jan 24 '13 16:01

Anlo


People also ask

How does NUnit decide what order to run tests in?

There is no facility in NUnit to order tests globally. Tests with an OrderAttribute argument are started before any tests without the attribute. Ordered tests are started in ascending order of the order argument. Among tests with the same order value or without the attribute, execution order is indeterminate.

How can you make a NUnit test case data driven?

The first way to create data driven tests is by using the [TestCase] attribute that NUnit provides. You can add multiple [TestCase] attributes for a single test method, and specify the combinations of input and expected output parameters that the test method should take.

How do you rerun failed test cases in NUnit?

For every failed test, write the test case name including the containing class name and the namespace to a file. Using nunit-console.exe, rerun the whole spec dll but filtered by that text file, so NUnit will run only the failed tests.

Which attribute in NUnit lets you execute a method before and after a test case?

The closest thing in nunit is the SetupFixture attribute, which allows you to tag a class to do setup/teardown for all test fixtures in a namespace; The SetUp method in a SetUpFixture is executed once before any of the fixtures contained in its namespace.


1 Answers

You've done nothing wrong.

If you open your test dll via NUnit test runner you will see all test are running successfully.
(I just verified your code with 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.
So, my suggestion is to use NUnit to run parameterized tests.

Btw, Resharper 7 has better support NUnit parameterized tests. And probably this issue won't appear in the latest Resharper version.

like image 116
Alexander Stepaniuk Avatar answered Sep 21 '22 01:09

Alexander Stepaniuk