Skip to content

Commit 9293efa

Browse files
authored
feat(nunit, xunit, specflow, reqnroll): titlePath (#574)
* feat(commons): add TestResult.titlePath * feat(nunit): implement titlePath * feat(nunit): remove .dll from assembly in titlePath * refactor(commons): refactor IdFunctions.cs * test(commons): assign names to param. fullName tests * test(commons): prefix method fullName test names * test(commons): add nested of generic fullName tests * test(commons): implement Type -> titlePath conversion * feat(xunit): implement titlePath * feat(reqnroll): implement titlePath * feat(specflow): implement titlePath
1 parent d675a6b commit 9293efa

File tree

9 files changed

+293
-33
lines changed

9 files changed

+293
-33
lines changed

Allure.NUnit/Core/AllureNUnitHelper.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel;
43
using System.Linq;
54
using System.Text;
65
using Allure.Net.Commons;
@@ -96,6 +95,7 @@ internal static TestResult CreateTestResult(ITest test)
9695
var testResult = new TestResult
9796
{
9897
name = test.Name,
98+
titlePath = EnumerateNamesFromTestFixtureToRoot(test).Reverse().ToList(),
9999
labels = new List<Label>
100100
{
101101
Label.Thread(),
@@ -135,6 +135,16 @@ TestStatus.Failed when IsBroken(result) => Status.broken,
135135
};
136136
}
137137

138+
static IEnumerable<string> EnumerateNamesFromTestFixtureToRoot(ITest test)
139+
{
140+
for (ITest suite = GetTestFixture(test); suite is not null; suite = suite.Parent)
141+
yield return suite switch
142+
{
143+
TestAssembly a => a.Assembly?.GetName()?.Name ?? a.Name,
144+
_ => suite.Name,
145+
};
146+
}
147+
138148
TestResultContainer CreateTestContainer() =>
139149
new()
140150
{
@@ -236,17 +246,17 @@ static string GetClassName(string classFullName)
236246
static TestFixture GetTestFixture(ITest test)
237247
{
238248
var currentTest = test;
239-
249+
240250
while (currentTest != null)
241251
{
242252
if (currentTest is TestFixture testFixture)
243253
{
244254
return testFixture;
245255
}
246-
256+
247257
currentTest = currentTest.Parent;
248258
}
249-
259+
250260
throw new InvalidOperationException(
251261
$"Could not find TestFixture in the hierarchy for test: {test.FullName}. " +
252262
$"Test type: {test.GetType().Name}"

Allure.Net.Commons.Tests/FunctionTests/IdTests.cs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,48 @@ public void TestUUIDGeneration()
2020
);
2121
}
2222

23-
[TestCase(typeof(IdTests), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests")]
24-
[TestCase(typeof(ClassWithoutNamespace), "Allure.Net.Commons.Tests:ClassWithoutNamespace")]
25-
[TestCase(typeof(MyClass), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass")]
26-
[TestCase(typeof(MyClass<>), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]")]
27-
[TestCase(typeof(MyClass<string>), "Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[System.String]")]
23+
[TestCase(
24+
typeof(IdTests),
25+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests",
26+
TestName = "FullNameOfNonGenericClass"
27+
)]
28+
[TestCase(
29+
typeof(ClassWithoutNamespace),
30+
"Allure.Net.Commons.Tests:ClassWithoutNamespace",
31+
TestName = "FullNameOfClassWithNoNamespace"
32+
)]
33+
[TestCase(
34+
typeof(MyClass),
35+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass",
36+
TestName = "FullNameOfNestedClass"
37+
)]
38+
[TestCase(
39+
typeof(MyClass<>),
40+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]",
41+
TestName = "FullNameOfNestedGenericClassDefinition"
42+
)]
43+
[TestCase(
44+
typeof(MyClass<string>),
45+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[System.String]",
46+
TestName = "FullNameOfNestedConstructedGenericClass"
47+
)]
2848
[TestCase(
2949
typeof(MyClass<MyClass<string, int>, MyClass<MyClass>>),
3050
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`2[" +
3151
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`2[System.String,System.Int32]," +
3252
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[" +
33-
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]]"
53+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass]]",
54+
TestName = "FullNameOfComplexConstructedGenericClass"
55+
)]
56+
[TestCase(
57+
typeof(MyClass<>.Nested),
58+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1+Nested[T]",
59+
TestName = "FullNameOfNestedClassOfGenericClassDefinition"
60+
)]
61+
[TestCase(
62+
typeof(MyClass<int>.Nested),
63+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1+Nested[System.Int32]",
64+
TestName = "FullNameOfNestedClassOfConstructedGenericClass"
3465
)]
3566
public void TestFullNameFromClass(Type targetClass, string expectedFullName)
3667
{
@@ -55,6 +86,7 @@ internal void MethodWithArgumentOfGenericUserType<T>(MyClass<T> _) { }
5586

5687
class MyClass<T>
5788
{
89+
public class Nested { }
5890
internal void GenericMethodOfGenericClass<V>(List<T> _, List<V> __) { }
5991
}
6092

@@ -63,21 +95,21 @@ class MyClass<T1, T2> { }
6395
[TestCase(
6496
nameof(MyClass.ParameterlessMethod),
6597
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass.ParameterlessMethod()",
66-
TestName = "ParameterlessMethod"
98+
TestName = "FullNameOfParameterlessMethod"
6799
)]
68100
[TestCase(
69101
nameof(MyClass.MethodWithParameterOfBuiltInType),
70102
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
71103
".MethodWithParameterOfBuiltInType(System.Int32)",
72-
TestName = "MethodWithParameterOfBuiltInType"
104+
TestName = "FullNameOfMethodWithParameterOfBuiltInType"
73105
)]
74106
[TestCase(
75107
nameof(MyClass.MethodWithParameterOfUserType),
76108
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
77109
".MethodWithParameterOfUserType(" +
78110
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
79111
")",
80-
TestName = "MethodWithParameterOfUserType"
112+
TestName = "FullNameOfMethodWithParameterOfUserType"
81113
)]
82114
[TestCase(
83115
nameof(MyClass.MethodWithTwoParameters),
@@ -86,41 +118,41 @@ class MyClass<T1, T2> { }
86118
"System.Int32," +
87119
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
88120
")",
89-
TestName = "MethodWithTwoParameters"
121+
TestName = "FullNameOfMethodWithTwoParameters"
90122
)]
91123
[TestCase(
92124
nameof(MyClass.MethodWithRefParameter),
93125
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
94126
".MethodWithRefParameter(System.Int32&)",
95-
TestName = "MethodWithRefParameter"
127+
TestName = "FullNameOfMethodWithRefParameter"
96128
)]
97129
[TestCase(
98130
nameof(MyClass.MethodWithGenericParameter),
99131
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
100132
".MethodWithGenericParameter[T]()",
101-
TestName = "MethodWithGenericParameter"
133+
TestName = "FullNameOfMethodWithGenericParameter"
102134
)]
103135
[TestCase(
104136
nameof(MyClass.MethodWithArgumentOfGenericType),
105137
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
106138
".MethodWithArgumentOfGenericType[T](T)",
107-
TestName = "MethodWithArgumentOfGenericType"
139+
TestName = "FullNameOfMethodWithArgumentOfGenericType"
108140
)]
109141
[TestCase(
110142
nameof(MyClass.MethodWithArgumentOfTypeParametrizedByGenericType),
111143
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
112144
".MethodWithArgumentOfTypeParametrizedByGenericType[T](" +
113145
"System.Collections.Generic.Dictionary`2[System.Int32,T]" +
114146
")",
115-
TestName = "MethodWithArgumentOfTypeParametrizedByGenericType"
147+
TestName = "FullNameOfMethodWithArgumentOfTypeParametrizedByGenericType"
116148
)]
117149
[TestCase(
118150
nameof(MyClass.MethodWithArgumentOfGenericUserType),
119151
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass" +
120152
".MethodWithArgumentOfGenericUserType[T](" +
121153
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.IdTests+MyClass`1[T]" +
122154
")",
123-
TestName = "MethodWithArgumentOfGenericUserType"
155+
TestName = "FullNameOfMethodWithArgumentOfGenericUserType"
124156
)]
125157
public void FullNameFromMethod(string methodName, string expectedFullName)
126158
{
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Allure.Net.Commons.Functions;
4+
using NUnit.Framework;
5+
6+
namespace Allure.Net.Commons.Tests.FunctionTests;
7+
8+
class TitlePathTests
9+
{
10+
[TestCase(
11+
typeof(TitlePathTests),
12+
"Allure.Net.Commons.Tests",
13+
"Allure",
14+
"Net",
15+
"Commons",
16+
"Tests",
17+
"FunctionTests",
18+
"TitlePathTests",
19+
TestName = "Outmost type with namespave"
20+
)]
21+
[TestCase(
22+
typeof(ClassWithoutNamespace),
23+
"Allure.Net.Commons.Tests",
24+
"ClassWithoutNamespace",
25+
TestName = "Outmost type no namespace"
26+
)]
27+
[TestCase(
28+
typeof(MyClass),
29+
"Allure.Net.Commons.Tests",
30+
"Allure",
31+
"Net",
32+
"Commons",
33+
"Tests",
34+
"FunctionTests",
35+
"TitlePathTests+MyClass",
36+
TestName = "Nested class"
37+
)]
38+
[TestCase(
39+
typeof(MyClass<>),
40+
"Allure.Net.Commons.Tests",
41+
"Allure",
42+
"Net",
43+
"Commons",
44+
"Tests",
45+
"FunctionTests",
46+
"TitlePathTests+MyClass`1[T]",
47+
TestName = "Nested generic class definition"
48+
)]
49+
[TestCase(
50+
typeof(MyClass<string>),
51+
"Allure.Net.Commons.Tests",
52+
"Allure",
53+
"Net",
54+
"Commons",
55+
"Tests",
56+
"FunctionTests",
57+
"TitlePathTests+MyClass`1[System.String]",
58+
TestName = "Nested constructed generic class - system type alias"
59+
)]
60+
[TestCase(
61+
typeof(MyClass<DateTime>),
62+
"Allure.Net.Commons.Tests",
63+
"Allure",
64+
"Net",
65+
"Commons",
66+
"Tests",
67+
"FunctionTests",
68+
"TitlePathTests+MyClass`1[System.DateTime]",
69+
TestName = "Nested constructed generic class - system type"
70+
)]
71+
[TestCase(
72+
typeof(MyClass<ClassWithoutNamespace>),
73+
"Allure.Net.Commons.Tests",
74+
"Allure",
75+
"Net",
76+
"Commons",
77+
"Tests",
78+
"FunctionTests",
79+
"TitlePathTests+MyClass`1[Allure.Net.Commons.Tests:ClassWithoutNamespace]",
80+
TestName = "Nested constructed generic class - custom type"
81+
)]
82+
[TestCase(
83+
typeof(MyClass<MyClass<string, int>, MyClass<MyClass>>),
84+
"Allure.Net.Commons.Tests",
85+
"Allure",
86+
"Net",
87+
"Commons",
88+
"Tests",
89+
"FunctionTests",
90+
"TitlePathTests+MyClass`2[" +
91+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass`2[System.String,System.Int32]," +
92+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass`1[" +
93+
"Allure.Net.Commons.Tests:Allure.Net.Commons.Tests.FunctionTests.TitlePathTests+MyClass]]",
94+
TestName = "Nested constructed generic class - complex"
95+
)]
96+
public void TestTitlePathByClass(Type targetClass, params string[] expectedTitlePath)
97+
{
98+
Assert.That(
99+
IdFunctions.CreateTitlePath(targetClass),
100+
Is.EqualTo(expectedTitlePath)
101+
);
102+
}
103+
104+
class MyClass
105+
{
106+
internal void ParameterlessMethod() { }
107+
internal void MethodWithParameterOfBuiltInType(int _) { }
108+
internal void MethodWithParameterOfUserType(MyClass _) { }
109+
internal void MethodWithTwoParameters(int _, MyClass __) { }
110+
internal void MethodWithRefParameter(ref int _) { }
111+
internal void MethodWithGenericParameter<T>() { }
112+
internal void MethodWithArgumentOfGenericType<T>(T _) { }
113+
internal void MethodWithArgumentOfTypeParametrizedByGenericType<T>(Dictionary<int, T> _) { }
114+
internal void MethodWithArgumentOfGenericUserType<T>(MyClass<T> _) { }
115+
}
116+
117+
class MyClass<T>
118+
{
119+
public class Nested<G> { }
120+
internal void GenericMethodOfGenericClass<V>(List<T> _, List<V> __) { }
121+
}
122+
123+
class MyClass<T1, T2> { }
124+
}

0 commit comments

Comments
 (0)