From 7a2021d001ed802309dda1985012fdc21a7937d0 Mon Sep 17 00:00:00 2001 From: Alexey Rumyantsev Date: Sat, 13 Feb 2021 23:59:28 +0700 Subject: [PATCH] Added support AllureDisplayIgnored for ignoring testcases. #24 --- .../AllureDisplayIgnoredAttribute.cs | 5 +++- src/allure-nunit/TestSamples/TestClass1.cs | 25 +++++++++++++++++++ src/allure-nunit/allure-nunit.csproj | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/allure-nunit/Attributes/AllureDisplayIgnoredAttribute.cs b/src/allure-nunit/Attributes/AllureDisplayIgnoredAttribute.cs index dfbeef6..ecda6aa 100644 --- a/src/allure-nunit/Attributes/AllureDisplayIgnoredAttribute.cs +++ b/src/allure-nunit/Attributes/AllureDisplayIgnoredAttribute.cs @@ -37,7 +37,7 @@ public void AfterTest(ITest suite) if (suite.HasChildren) { var ignoredTests = - suite.Tests.Where(t => t.RunState == RunState.Ignored || t.RunState == RunState.Skipped); + GetAllTests(suite).Where(t => t.RunState == RunState.Ignored || t.RunState == RunState.Skipped); foreach (var test in ignoredTests) { AllureLifecycle.Instance.UpdateTestContainer(_ignoredContainerId, t => t.children.Add(test.Id)); @@ -71,6 +71,9 @@ public void AfterTest(ITest suite) } } + private static IEnumerable GetAllTests(ITest test) => + test.Tests.Concat(test.Tests.SelectMany(GetAllTests)); + public ActionTargets Targets => ActionTargets.Suite; } } \ No newline at end of file diff --git a/src/allure-nunit/TestSamples/TestClass1.cs b/src/allure-nunit/TestSamples/TestClass1.cs index ddb1bbd..796b85a 100644 --- a/src/allure-nunit/TestSamples/TestClass1.cs +++ b/src/allure-nunit/TestSamples/TestClass1.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Threading.Tasks; using Allure.Commons; using NUnit.Allure.Attributes; @@ -46,6 +47,21 @@ public void SimpleTestIgnored2() { } + [Test] + [TestCase("a")] + [TestCase("b", Ignore = "Case")] + public void TestCaseIgnoreOne(string a) + { + Console.WriteLine(a); + } + + [Test] + [TestCaseSource(typeof(TestClass1), nameof(Data))] + public void TestCaseData(string a) + { + Console.WriteLine(a); + } + [Test(Author = "unickq")] [Category("SampleTag")] [Description("OLOLO")] @@ -57,5 +73,14 @@ public void SimpleTestFailed() Console.WriteLine("Failed"); Assert.DoesNotThrow(() => { throw new Exception("I'm an exception"); }); } + + private static IEnumerable Data + { + get + { + yield return new TestCaseData("Test").SetName("{m}_NotExist"); + yield return new TestCaseData("Ignore").SetName("{m}_NotExist").Ignore("Test"); + } + } } } \ No newline at end of file diff --git a/src/allure-nunit/allure-nunit.csproj b/src/allure-nunit/allure-nunit.csproj index 79921fb..787732d 100644 --- a/src/allure-nunit/allure-nunit.csproj +++ b/src/allure-nunit/allure-nunit.csproj @@ -1,7 +1,7 @@  - net45;netstandard20 + net45;netstandard2.0 1.0.0 1.0.0 1.0.0