Skip to content

Commit cbbb317

Browse files
committed
test(nunit): add more label and parameter tests
1 parent 6c77e29 commit cbbb317

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1025
-16
lines changed

tests/Allure.NUnit.Tests/LabelTests.cs renamed to tests/Allure.NUnit.Tests/CustomLabelTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33

44
namespace Allure.NUnit.Tests;
55

6-
internal class LabelTests
6+
internal class CustomLabelTests
77
{
88
public static IEnumerable<TestDataRow<AllureSampleRegistryEntry>> GetCustomLabelSamples()
99
{
10-
IEnumerable<AllureSampleRegistryEntry> labelSamples = [
11-
AllureSampleRegistry.AttributeLabelOnClass,
12-
AllureSampleRegistry.AttributeLabelOnMethod,
10+
IEnumerable<AllureSampleRegistryEntry> samples = [
11+
AllureSampleRegistry.LabelAttributeOnClass,
12+
AllureSampleRegistry.LabelAttributeOnMethod,
13+
AllureSampleRegistry.LabelAttributeOnBaseClass,
1314
AllureSampleRegistry.AddLabelFromSetUp,
1415
AllureSampleRegistry.AddLabelFromTest,
1516
AllureSampleRegistry.AddLabelFromTearDown,
1617
];
1718

18-
return labelSamples.Select(static (sample) =>
19+
return samples.Select(static (sample) =>
1920
new TestDataRow<AllureSampleRegistryEntry>(sample, DisplayName: sample.Id));
2021
}
2122

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Text.Json.Nodes;
2+
using Allure.Testing;
3+
4+
namespace Allure.NUnit.Tests;
5+
6+
internal class EpicTests
7+
{
8+
public static IEnumerable<TestDataRow<AllureSampleRegistryEntry>> GetEpicSamples()
9+
{
10+
IEnumerable<AllureSampleRegistryEntry> samples = [
11+
AllureSampleRegistry.EpicAttributeOnClass,
12+
AllureSampleRegistry.EpicAttributeOnMethod,
13+
AllureSampleRegistry.EpicAttributeOnBaseClass,
14+
AllureSampleRegistry.AddEpicFromSetUp,
15+
AllureSampleRegistry.AddEpicFromTest,
16+
AllureSampleRegistry.AddEpicFromTearDown,
17+
];
18+
19+
return samples.Select(static (sample) =>
20+
new TestDataRow<AllureSampleRegistryEntry>(sample, DisplayName: sample.Id));
21+
}
22+
23+
[Test]
24+
[MethodDataSource(nameof(GetEpicSamples))]
25+
public async Task CheckEpicIsAdded(AllureSampleRegistryEntry sample)
26+
{
27+
var results = await AllureSampleRunner.RunAsync(sample);
28+
29+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
30+
var nodes = results.TestResults[0]["labels"].AsArray().Cast<JsonObject>();
31+
await Assert.That(nodes).Any(
32+
l =>
33+
{
34+
return (string)l["name"] == "epic" && (string)l["value"] == "foo";
35+
}
36+
);
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Text.Json.Nodes;
2+
using Allure.Testing;
3+
4+
namespace Allure.NUnit.Tests;
5+
6+
internal class FeatureTests
7+
{
8+
public static IEnumerable<TestDataRow<AllureSampleRegistryEntry>> GetFeatureSamples()
9+
{
10+
IEnumerable<AllureSampleRegistryEntry> samples = [
11+
AllureSampleRegistry.FeatureAttributeOnClass,
12+
AllureSampleRegistry.FeatureAttributeOnMethod,
13+
AllureSampleRegistry.FeatureAttributeOnBaseClass,
14+
AllureSampleRegistry.AddFeatureFromSetUp,
15+
AllureSampleRegistry.AddFeatureFromTest,
16+
AllureSampleRegistry.AddFeatureFromTearDown,
17+
];
18+
19+
return samples.Select(static (sample) =>
20+
new TestDataRow<AllureSampleRegistryEntry>(sample, DisplayName: sample.Id));
21+
}
22+
23+
[Test]
24+
[MethodDataSource(nameof(GetFeatureSamples))]
25+
public async Task CheckFeatureIsAdded(AllureSampleRegistryEntry sample)
26+
{
27+
var results = await AllureSampleRunner.RunAsync(sample);
28+
29+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
30+
var nodes = results.TestResults[0]["labels"].AsArray().Cast<JsonObject>();
31+
await Assert.That(nodes).Any(
32+
l =>
33+
{
34+
return (string)l["name"] == "feature" && (string)l["value"] == "foo";
35+
}
36+
);
37+
}
38+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System.Text.Json.Nodes;
2+
using Allure.Testing;
3+
4+
namespace Allure.NUnit.Tests;
5+
6+
class ParameterTests
7+
{
8+
public static IEnumerable<TestDataRow<AllureSampleRegistryEntry>> GetSingleParameterSamples()
9+
{
10+
IEnumerable<AllureSampleRegistryEntry> samples = [
11+
AllureSampleRegistry.AddParameterFromSetUp,
12+
AllureSampleRegistry.AddParameterFromTest,
13+
AllureSampleRegistry.AddParameterFromTearDown,
14+
AllureSampleRegistry.OneNUnitTestCaseWithOneParameter,
15+
];
16+
17+
return samples.Select(static (sample) =>
18+
new TestDataRow<AllureSampleRegistryEntry>(sample, DisplayName: sample.Id));
19+
}
20+
21+
[Test]
22+
[MethodDataSource(nameof(GetSingleParameterSamples))]
23+
public async Task CheckParameterIsAdded(AllureSampleRegistryEntry sample)
24+
{
25+
var results = await AllureSampleRunner.RunAsync(sample);
26+
27+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
28+
var nodes = results.TestResults[0]["parameters"].AsArray().Cast<JsonObject>();
29+
await Assert.That(nodes).ContainsOnly(
30+
p => (string)p["name"] == "foo" && (string)p["value"] == "\"bar\""
31+
);
32+
}
33+
34+
[Test]
35+
public async Task CheckMaskedParameter()
36+
{
37+
var results = await AllureSampleRunner.RunAsync(AllureSampleRegistry.MaskedParameter);
38+
39+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
40+
41+
var parameters = results.TestResults[0]["parameters"].AsArray().Cast<JsonObject>();
42+
await Assert.That(parameters).HasSingleItem().And.All(
43+
static (p) => (string)p["mode"] == "masked"
44+
);
45+
}
46+
47+
[Test]
48+
public async Task CheckHiddenParameter()
49+
{
50+
var results = await AllureSampleRunner.RunAsync(AllureSampleRegistry.HiddenParameter);
51+
52+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
53+
54+
var parameters = results.TestResults[0]["parameters"].AsArray().Cast<JsonObject>();
55+
await Assert.That(parameters).HasSingleItem().And.All(
56+
static (p) => (string)p["mode"] == "hidden"
57+
);
58+
}
59+
60+
[Test]
61+
public async Task CheckExcludedParameter()
62+
{
63+
var results = await AllureSampleRunner.RunAsync(AllureSampleRegistry.ExcludedParameter);
64+
65+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(2);
66+
67+
var testResult1 = results.TestResults[0];
68+
var testResult2 = results.TestResults[1];
69+
70+
var testResult1Parameters = testResult1["parameters"].AsArray().Cast<JsonObject>();
71+
var testResult2Parameters = testResult2["parameters"].AsArray().Cast<JsonObject>();
72+
await Assert.That(testResult1Parameters).Any(
73+
static (p) => (string)p["name"] == "timestamp" && (bool)p["excluded"] == true
74+
);
75+
await Assert.That(testResult2Parameters).Any(
76+
static (p) => (string)p["name"] == "timestamp" && (bool)p["excluded"] == true
77+
);
78+
79+
// It must not affect historyId
80+
await Assert.That((string)testResult1["historyId"]).IsEqualTo((string)testResult2["historyId"]);
81+
}
82+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Text.Json.Nodes;
2+
using Allure.Testing;
3+
4+
namespace Allure.NUnit.Tests;
5+
6+
internal class ParentSuiteTests
7+
{
8+
public static IEnumerable<TestDataRow<AllureSampleRegistryEntry>> GetParentSuiteSamples()
9+
{
10+
IEnumerable<AllureSampleRegistryEntry> samples = [
11+
AllureSampleRegistry.ParentSuiteAttributeOnClass,
12+
AllureSampleRegistry.ParentSuiteAttributeOnMethod,
13+
AllureSampleRegistry.ParentSuiteAttributeOnBaseClass,
14+
AllureSampleRegistry.AddParentSuiteFromSetUp,
15+
AllureSampleRegistry.AddParentSuiteFromTest,
16+
AllureSampleRegistry.AddParentSuiteFromTearDown,
17+
];
18+
19+
return samples.Select(static (sample) =>
20+
new TestDataRow<AllureSampleRegistryEntry>(sample, DisplayName: sample.Id));
21+
}
22+
23+
[Test]
24+
[MethodDataSource(nameof(GetParentSuiteSamples))]
25+
public async Task CheckParentSuiteIsAdded(AllureSampleRegistryEntry sample)
26+
{
27+
var results = await AllureSampleRunner.RunAsync(sample);
28+
29+
await Assert.That(results.TestResults.Cast<JsonObject>()).Count().IsEqualTo(1);
30+
var nodes = results.TestResults[0]["labels"].AsArray().Cast<JsonObject>();
31+
await Assert.That(nodes).Any(
32+
l =>
33+
{
34+
return (string)l["name"] == "parentSuite" && (string)l["value"] == "foo";
35+
}
36+
);
37+
}
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Allure.Net.Commons;
2+
using NUnit.Framework;
3+
4+
namespace Allure.NUnit.Examples
5+
{
6+
[AllureNUnit]
7+
public class TestsClass
8+
{
9+
[SetUp]
10+
public void SetUp()
11+
{
12+
AllureApi.AddEpic("foo");
13+
}
14+
15+
[Test]
16+
public void TestMethod() { }
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Allure.Net.Commons;
2+
using NUnit.Framework;
3+
4+
namespace Allure.NUnit.Examples
5+
{
6+
[AllureNUnit]
7+
public class TestsClass
8+
{
9+
[TearDown]
10+
public void TearDown()
11+
{
12+
AllureApi.AddEpic("foo");
13+
}
14+
15+
[Test]
16+
public void TestMethod() { }
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Allure.Net.Commons;
2+
using NUnit.Framework;
3+
4+
namespace Allure.NUnit.Examples
5+
{
6+
[AllureNUnit]
7+
public class TestsClass
8+
{
9+
[Test]
10+
public void TestMethod()
11+
{
12+
AllureApi.AddEpic("foo");
13+
}
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Allure.Net.Commons;
2+
using NUnit.Framework;
3+
4+
namespace Allure.NUnit.Examples
5+
{
6+
[AllureNUnit]
7+
public class TestsClass
8+
{
9+
[SetUp]
10+
public void SetUp()
11+
{
12+
AllureApi.AddFeature("foo");
13+
}
14+
15+
[Test]
16+
public void TestMethod() { }
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Allure.Net.Commons;
2+
using NUnit.Framework;
3+
4+
namespace Allure.NUnit.Examples
5+
{
6+
[AllureNUnit]
7+
public class TestsClass
8+
{
9+
[TearDown]
10+
public void TearDown()
11+
{
12+
AllureApi.AddFeature("foo");
13+
}
14+
15+
[Test]
16+
public void TestMethod() { }
17+
}
18+
}

0 commit comments

Comments
 (0)