Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Allure.NUnit.Examples/AllureIgnoredTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ private static IEnumerable Data
{
get
{
yield return new TestCaseData("Ignore").SetName("{m}_NotExist");
yield return new TestCaseData("NotIgnore").SetName("{m}_NotExist ignored").Ignore("Test");
yield return new TestCaseData("NotIgnore").SetName("{m}_NotExist");
yield return new TestCaseData("Ignore").SetName("{m}_NotExist ignored").Ignore("Test");
}
}

Expand All @@ -25,6 +25,14 @@ public void IgnoredTest()
}


[TestCase("a")]
[TestCase("b")]
[Ignore("Foo")]
public void IgnoredTestCase(string data)
{
}


[Test]
[TestCase("a")]
[TestCase("b", Ignore = "Case")]
Expand Down
24 changes: 17 additions & 7 deletions Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public void AfterTest(ITest suite)
suite = (TestSuite) suite;
if (suite.HasChildren)
{
var ignoredTests =
GetAllTests(suite).Where(
t => t.RunState == RunState.Ignored
|| t.RunState == RunState.Skipped
);
var ignoredTests = GetIgnoredTests(suite);
foreach (var test in ignoredTests)
{
this.EmitResultForIgnoredTestInTestPlan(test);
Expand All @@ -50,11 +46,25 @@ public void AfterTest(ITest suite)

public ActionTargets Targets => ActionTargets.Suite;

private static IEnumerable<ITest> GetAllTests(ITest test)
static IEnumerable<ITest> GetIgnoredTests(ITest suite, bool parentIgnored = false)
{
return test.Tests.Concat(test.Tests.SelectMany(GetAllTests));
return suite.Tests.SelectMany(test =>
{
bool isIgnored = parentIgnored || IsTestIgnored(test);
return test.IsSuite
? GetIgnoredTests(test, isIgnored)
: isIgnored
? Enumerable.Repeat(test, 1)
: Enumerable.Empty<ITest>();
});
}

static bool IsTestIgnored(ITest test) => test.RunState switch
{
RunState.Ignored or RunState.Skipped => true,
_ => false
};

void EmitResultForIgnoredTestInTestPlan(ITest test)
{
var ignoredTestResult = AllureNUnitHelper.CreateTestResult(test);
Expand Down
Loading