From 1e03ad7cc8c99bba262bd3dc21e1ef47ac5698e6 Mon Sep 17 00:00:00 2001 From: Michael Blake Date: Thu, 30 Apr 2020 14:54:35 +0100 Subject: [PATCH 1/2] Add Machine Spec Filtering --- docs/filter.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/filter.md b/docs/filter.md index 0b26b928..2d4d26f9 100644 --- a/docs/filter.md +++ b/docs/filter.md @@ -18,6 +18,7 @@ supported by popular unit test frameworks. | -------------- | -------------------- | | MSTest | | | Xunit | | +| MSpec | | Allowed **operators**: * `=` implies an exact match @@ -27,7 +28,7 @@ Allowed **operators**: **Value** is a string. All the lookups are case insensitive. -**Escape Sequences** must be used to represent characters in the value that have special meanings in the filter, i.e. filter operators. +**Escape Sequences** must be used to represent characters in the value that have special meanings in the filter, i.e. filter operators. | Escape Sequence | Represents | | -------------- | -------------------- | @@ -137,3 +138,27 @@ 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. | + +### Machine Spec + +| Expression | What it does? | +| ---------- | ------------- | +| `dotnet test --filter DisplayName=MSpecNamespace.TestClass1.Test1` | Runs only one test `MSpecNamespace.TestClass1.Test1`. | +| `dotnet test --filter Tag!=SlowTests` | Runs all tests except tests with `[Tags("SlowTests")]` | +| `dotnet test --filter Subject~WebAPI` | Runs tests whose `Subject` name contains `WebAPI`. | + +#### Using traits for filter +```CSharp +namespace MSpecNamespace +{ + [Subject(typeof(TestClass1))] + public class TestClass1Tests + { + [Tags("SlowTests")] + public void Foo() + { + } + } +} +``` +In above code we defined traits with keys `Subject` and `Tags` which can be used for filtering. From 041722d4dddfb8b7be570d0b11ac4fc446fee722 Mon Sep 17 00:00:00 2001 From: Michael Blake Date: Thu, 30 Apr 2020 15:12:09 +0100 Subject: [PATCH 2/2] Improve MSpec sample --- docs/filter.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/filter.md b/docs/filter.md index 2d4d26f9..39a13680 100644 --- a/docs/filter.md +++ b/docs/filter.md @@ -152,13 +152,18 @@ In above code we defined traits with keys `Category` and `Priority` which can be namespace MSpecNamespace { [Subject(typeof(TestClass1))] + [Tags("SlowTests")] public class TestClass1Tests { - [Tags("SlowTests")] - public void Foo() - { - } + Establish context = () => + _class = new TestClass1(); + + Because of = () => + _result = _class.Do(); + + It should_have_assertions = () => + _result.ShouldNotBeNull(); } } ``` -In above code we defined traits with keys `Subject` and `Tags` which can be used for filtering. +In above code we defined traits with keys `Subject` and `Tags` (Tag) which can be used for filtering.