diff --git a/Allure.NUnit/Core/AllureExtensions.cs b/Allure.NUnit/Core/AllureExtensions.cs index 1776efb6..d1b9d3eb 100644 --- a/Allure.NUnit/Core/AllureExtensions.cs +++ b/Allure.NUnit/Core/AllureExtensions.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using Allure.Net.Commons; +using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; namespace NUnit.Allure.Core @@ -204,6 +205,15 @@ public static async Task WrapInStepAsync( } } + internal const string DESELECTED_BY_TESTPLAN_KEY + = "DESELECTED_BY_TESTPLAN"; + + static internal void Deselect(this ITest test) => + test.Properties.Add(DESELECTED_BY_TESTPLAN_KEY, true); + + static internal bool IsDeselected(this ITest test) => + test.Properties.ContainsKey(DESELECTED_BY_TESTPLAN_KEY); + [Obsolete( "Use AllureLifecycle.AddScreenDiff instance method instead to " + "add a screen diff to the current test." diff --git a/Allure.NUnit/Core/AllureNUnitAttribute.cs b/Allure.NUnit/Core/AllureNUnitAttribute.cs index 4a67d4ac..9309201b 100644 --- a/Allure.NUnit/Core/AllureNUnitAttribute.cs +++ b/Allure.NUnit/Core/AllureNUnitAttribute.cs @@ -35,12 +35,17 @@ public void BeforeTest(ITest test) => if (!test.IsSuite) { - helper.StartTestContainer(); // A container for SetUp/TearDown methods - helper.StartTestCase(); + helper.PrepareTestContext(); } }); - public void AfterTest(ITest test) => + public void AfterTest(ITest test) + { + if (test.IsDeselected()) + { + return; + } + RunHookInRestoredAllureContext(test, () => { if (_allureNUnitHelper.TryGetValue(test.Id, out var helper)) @@ -52,14 +57,17 @@ public void AfterTest(ITest test) => } else if (IsSuiteWithNoAfterFixtures(test)) { - // If a test fixture contains a OneTimeTearDown method - // with the [AllureAfter] attribute, the corresponding - // container is closed in StopContainerAspect instead. + // If a test class has no class-scope after-feature + // (i.e., a method with both [OneTimeTearDown] and + // [AllureAfter]), the class-scope container is closed + // here. Otherwise, it's closed in StopContainerAspect + // instead. helper.StopTestContainer(); } } }); - + } + public ActionTargets Targets => ActionTargets.Test | ActionTargets.Suite; diff --git a/Allure.NUnit/Core/AllureNUnitHelper.cs b/Allure.NUnit/Core/AllureNUnitHelper.cs index 9c958792..7e2a6ed9 100644 --- a/Allure.NUnit/Core/AllureNUnitHelper.cs +++ b/Allure.NUnit/Core/AllureNUnitHelper.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using Allure.Net.Commons; +using Allure.Net.Commons.TestPlan; using Newtonsoft.Json.Linq; using NUnit.Allure.Attributes; using NUnit.Framework; @@ -40,73 +42,26 @@ internal void StartTestContainer() }); } - internal void StartTestCase() + internal void PrepareTestContext() { - var testResult = new TestResult + var testResult = this.CreateTestResult(); + if (IsSelectedByTestPlan(testResult)) { - uuid = string.Concat( - Guid.NewGuid().ToString(), - "-tr-", - _test.Id - ), - name = _test.Name, - historyId = _test.FullName, - fullName = _test.FullName, - labels = new List