Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit: how to run only tests that have specific property (priority or type)

I want to have the ability to selectively run the NUnit tests based on several criteria. In my case, the selection will be based on: Test Priority and/or Test Type.

The test class/method would look like that:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class MathTests
  {
    [Test, Property("Priority", "Critical"), Property("Type", "Fully automatic")]
public void AdditionTest()
      { /* ... */ }

    [Test, Property("Priority", "High"), Property("Type", "Partly automatic")]
public void MultiplicationTest()
      { /* ... */ }
  }
}

I want to run only the tests that have "Priority" = "Critical" AND "Type" = "Fully automatic".

Is it possible to implement such selection with the NUnit? I know it is possible to select tests belonging to specific "categories" for execution, but it is only 1 criterion...

like image 602
andrey1492 Avatar asked Apr 13 '12 11:04

andrey1492


People also ask

How do you prioritize test cases in NUnit?

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.

Which attribute is used to run the test before each test method is called in NUnit?

This attribute is used inside a TestFixture to provide a common set of functions that are performed just before each test method is called.

How do I exclude a test in NUnit?

IgnoreAttribute (NUnit 2.0) The ignore attribute is an attribute to not run a test or test fixture for a period of time. The person marks either a Test or a TestFixture with the Ignore Attribute. The running program sees the attribute and does not run the test or tests.


1 Answers

According to the Nunit Console Manual:

The following command runs only the tests in the BaseLine category:

nunit-console myassembly.dll /include:Database

Multiple categories may be specified on either option, by using commas to separate them.

So I would expect something like nunit-console myassembly.dll /include:Priority,Critical to do what you want (I havent tested it).

like image 148
gbanfill Avatar answered Nov 15 '22 05:11

gbanfill