2

NUnit 3 has "--where" parameter in console that allows us to select different tests to run. It can include different namespaces or test categories.

I want (but don't know how) to include some namespaces to run tests. I have specific examples and I ask you for help.

Let's assume we have the next namespaces with tests:

  1. Project.MainSuite (includes 1 tests)
  2. Project.MainSuite.Category1 (has 2 tests)
  3. Project.MainSuite.Category1.TestSuite1 (has 3 tests)

How to run the next tests using --where parameter:

  1. Tests only from Project.MainSuite.Category1 (2 tests should be run)
  2. Tests from Project.MainSuite.Category1 and Project.MainSuite.Category1.TestSuite1 together (5 tests should be run)
  3. All test from Project.MainSuite including sub-namespaces (6 tests should be run)

Thanks in advance for your help.

Denis Koreyba
  • 3,144
  • 1
  • 31
  • 49

2 Answers2

2

I recently ran into a similar issue and wanted to get a solid answer for this.

The short answer to your question is that you cannot do what you are asking without being more explicit.

When you run your tests with a where clause of --where "test == Project.MainSuite" (the highest namespace in your project), it will run all of the tests in that namespace and all sub-namespaces.

If you run your tests with a where clause of --where "test == Project.MainSuite.Category1.TestSuite1" (the lowest sub namespace in Project.MainSuite), it will only run all of the tests inside of that namespace.

You can do a few things to get what you are trying to accomplish.

1. Tests only from Project.MainSuite.Category1

--where "class == Project.MainSuite.Category1.ClassWithTests"

Just be explicit about the classes that are inside of this namespace. Or if you are worried about adding more tests inside of this namespace in the future and don't want to update the script to run the tests. You can add Category attributes to the Suites/Tests inside this namespace and run them based off that Category.

--where "cat == TestsInCategory1Namespace"

2. Tests from Project.MainSuite.Category1 and Project.MainSuite.Category1.TestSuite1 together

Similarly for this scenario, you can combine the category and the class clause together. --where "cat == TestsInCategory1Namespace and class == Project.MainSuite.Category1.TestSuite1"

3. All test from Project.MainSuite including sub-namespaces

--where test == Project.MainSuite

KingJames
  • 21
  • 3
0

Does this help? Test Selection Language

this should work for categorys --where "cat == SmokeTests" --noresult

this for namespace: --where test == "My.Namespace" and cat == Urgent

Niklas Berglund
  • 3,563
  • 4
  • 32
  • 32
Perazim
  • 1,501
  • 3
  • 19
  • 42
  • I asked to help me with specific 3 examples. The example you given works only with the third example. Can you give examples for 2 others? – Denis Koreyba Sep 09 '16 at 07:21
  • maybe this is also interesting http://stackoverflow.com/questions/40010519/run-all-tests-in-namespace-using-nunit3-console-exe – Perazim Oct 14 '16 at 08:20