Skip to content

Commit

Permalink
Update filter.md for NUnit (#14987)
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisTerje authored Jan 23, 2025
1 parent f70bb54 commit 270d144
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ supported by popular unit test frameworks.
| -------------- | -------------------- |
| MSTest | <ul><li>FullyQualifiedName</li><li>Name</li><li>ClassName</li><li>Priority</li><li>TestCategory</li></ul> |
| Xunit | <ul><li>FullyQualifiedName</li><li>DisplayName</li><li>Traits</li></ul> |
| NUnit | <ul><li>FullyQualifiedName</li><li>Name</li><li>Priority</li><li>TestCategory</li><li>Category</li><li>Property</li></ul>|

Allowed **operators**:

Expand Down Expand Up @@ -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.


0 comments on commit 270d144

Please sign in to comment.