From 270d144c1775c13f6a12567f7d9a835e3d1507b8 Mon Sep 17 00:00:00 2001 From: Terje Sandstrom Date: Thu, 23 Jan 2025 19:36:06 +0100 Subject: [PATCH] Update filter.md for NUnit (#14987) --- docs/filter.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/filter.md b/docs/filter.md index ecd6bf9351..9cd974f300 100644 --- a/docs/filter.md +++ b/docs/filter.md @@ -20,6 +20,7 @@ supported by popular unit test frameworks. | -------------- | -------------------- | | MSTest | | | Xunit | | +| NUnit | | Allowed **operators**: @@ -145,3 +146,49 @@ In above code we defined traits with keys `Category` and `Priority` which can be | `dotnet test --filter "FullyQualifiedName~TestClass1\|Category=Nightly"` | Runs tests which have `TestClass1` in FullyQualifiedName **or** Category is Nightly. | | `dotnet test --filter "FullyQualifiedName~TestClass1&Category=Nightly"` | Runs tests which have `TestClass1` in FullyQualifiedName **and** Category is Nightly. | | `dotnet test --filter "(FullyQualifiedName~TestClass1&Category=Nightly)\|Priority=1"` | Runs tests which have either FullyQualifiedName contains `TestClass1` and Category is CategoryA or Priority is 1. | + +### NUnit + +```csharp +namespace NUnitTestNamespace; + +public class TestClass +{ + [Property("Priority","1")] + [Test] + public void Test1() + { + Assert.Pass(); + } + + [Property("Whatever", "SomeValue")] + [Test] + public void Test2() + { + Assert.Pass(); + } + + [Category("SomeCategory")] + [Test] + public void Test3() + { + Assert.Pass(); + } +} +``` + +#### Usage of the filters + +| Expression | What it does? | +| ---------- | ------------- | +| `dotnet test --filter FullyQualifiedName=NUnitTestNamespace.TestClass.Test1` | Runs only the given test | +| `dotnet test --filter Name=Test1` | Runs all tests whose test name (method) equals `Test1`. | +| `dotnet test --filter Name=TestClass` | Runs tests within all classes named `TestClass`. | +| `dotnet test --filter Name=NUnitTestNamespace` | Runs all tests within the namespace `NUnitTestNamespace`. | +| `dotnet test --filter Priority=1` | Runs tests with property named Priority and value = 1`. | +| `dotnet test --filter Whatever=TestClass` | Runs tests with property named `Whatever` and value = `SomeValue`. | +| `dotnet test --filter Category=SomeCategory` | Runs tests with category set to `SomeCategory`. Note: You can also use TestCategory in the filter. | + +Logical operators works the same as for the other frameworks. + +