Skip to content

Commit 1d3ff7f

Browse files
authored
fix(nunit): properly report ignored test cases (#570)
* chore: add ignore all cases example * chore: fix ignored example with tc source * fix: report leaves only in AllureDisplayIgnored
1 parent cfd74bc commit 1d3ff7f

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Allure.NUnit.Examples/AllureIgnoredTest.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ private static IEnumerable Data
1313
{
1414
get
1515
{
16-
yield return new TestCaseData("Ignore").SetName("{m}_NotExist");
17-
yield return new TestCaseData("NotIgnore").SetName("{m}_NotExist ignored").Ignore("Test");
16+
yield return new TestCaseData("NotIgnore").SetName("{m}_NotExist");
17+
yield return new TestCaseData("Ignore").SetName("{m}_NotExist ignored").Ignore("Test");
1818
}
1919
}
2020

@@ -25,6 +25,14 @@ public void IgnoredTest()
2525
}
2626

2727

28+
[TestCase("a")]
29+
[TestCase("b")]
30+
[Ignore("Foo")]
31+
public void IgnoredTestCase(string data)
32+
{
33+
}
34+
35+
2836
[Test]
2937
[TestCase("a")]
3038
[TestCase("b", Ignore = "Case")]

Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ public void AfterTest(ITest suite)
3636
suite = (TestSuite) suite;
3737
if (suite.HasChildren)
3838
{
39-
var ignoredTests =
40-
GetAllTests(suite).Where(
41-
t => t.RunState == RunState.Ignored
42-
|| t.RunState == RunState.Skipped
43-
);
39+
var ignoredTests = GetIgnoredTests(suite);
4440
foreach (var test in ignoredTests)
4541
{
4642
this.EmitResultForIgnoredTestInTestPlan(test);
@@ -50,11 +46,25 @@ public void AfterTest(ITest suite)
5046

5147
public ActionTargets Targets => ActionTargets.Suite;
5248

53-
private static IEnumerable<ITest> GetAllTests(ITest test)
49+
static IEnumerable<ITest> GetIgnoredTests(ITest suite, bool parentIgnored = false)
5450
{
55-
return test.Tests.Concat(test.Tests.SelectMany(GetAllTests));
51+
return suite.Tests.SelectMany(test =>
52+
{
53+
bool isIgnored = parentIgnored || IsTestIgnored(test);
54+
return test.IsSuite
55+
? GetIgnoredTests(test, isIgnored)
56+
: isIgnored
57+
? Enumerable.Repeat(test, 1)
58+
: Enumerable.Empty<ITest>();
59+
});
5660
}
5761

62+
static bool IsTestIgnored(ITest test) => test.RunState switch
63+
{
64+
RunState.Ignored or RunState.Skipped => true,
65+
_ => false
66+
};
67+
5868
void EmitResultForIgnoredTestInTestPlan(ITest test)
5969
{
6070
var ignoredTestResult = AllureNUnitHelper.CreateTestResult(test);

0 commit comments

Comments
 (0)