Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix identification properties and parameter formatting #395

Merged
merged 21 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d35934d
Bump NUnit for test and example projects
delatrie Oct 4, 2023
23abad2
Add json schemas for allureConfig and testplan
delatrie Sep 21, 2023
7e7a77a
Fix schema for allure-xunit and allure-specflow config
delatrie Sep 21, 2023
cec3b19
Add legacy naming switch to config
delatrie Oct 4, 2023
7fb4a1a
Update schema links to current branch
delatrie Oct 11, 2023
799a470
Add schema links update task to release workflow
delatrie Oct 11, 2023
4d1a285
Implement UUID and method-based fullName algorithms
delatrie Oct 4, 2023
a6a992a
Common fns to calculate testCaseId, historyId and parameter value
delatrie Oct 11, 2023
44e2a81
Add docstrings to new id-related functions
delatrie Oct 11, 2023
7ea4f6d
Add function to create fullName from class
delatrie Oct 11, 2023
0009635
Fix allureConfig item type for allure-nunit examples
delatrie Oct 11, 2023
a0abe8b
Add missing setter for UseLegacyIds config property
delatrie Oct 11, 2023
0f635d5
Add framework label factory
delatrie Oct 11, 2023
633dd82
Fix uuid, fullName, historyId, testCaseId for allure-nunit
delatrie Oct 11, 2023
ec8b66b
Apply custom formatters to step title and parameters
delatrie Oct 11, 2023
faefd5a
Add language label to commons and NUnit
delatrie Oct 12, 2023
61c8804
Fix uuid, fullName, historyId, testCaseId for allure-xunit
delatrie Oct 12, 2023
ee19007
Add no-formatters step helper overloads back to public API
delatrie Oct 12, 2023
b00a6b5
Revert autoedit this removal from StepFunctionTests.cs
delatrie Oct 12, 2023
865b0d0
Fix uuid, fullName, historyId, testCaseId for allure-specflow
delatrie Oct 12, 2023
626170e
Implement requested changes
delatrie Oct 12, 2023
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
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ jobs:
run: |
sed -i -e '/<PropertyGroup>/,/<\/PropertyGroup>/ s|<Version>[0-9a-zA-Z.|-]*</Version>|<Version>${{ env.release_version }}</Version>|g' ./Directory.Build.props
cat ./Directory.Build.props
- name: "Update schema links"
run: |
sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit/Schemas/allureConfig.schema.json
cat ./Allure.NUnit/Schemas/allureConfig.schema.json
sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.XUnit/Schemas/allureConfig.schema.json
cat ./Allure.XUnit/Schemas/allureConfig.schema.json
sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json
cat ./Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit/allureConfig.json
cat ./Allure.NUnit/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit.Examples/allureConfig.json
cat ./Allure.NUnit.Examples/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.XUnit.Examples/allureConfig.json
cat ./Allure.XUnit.Examples/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin/allureConfig.Template.json
cat ./Allure.SpecFlowPlugin/allureConfig.Template.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Features/allureConfig.json
cat ./Allure.Features/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin.Tests/allureConfig.json
cat ./Allure.SpecFlowPlugin.Tests/allureConfig.json
- name: "Commit release version and create tag"
run: |
git commit -am "release ${{ env.release_version }}"
Expand Down
4 changes: 2 additions & 2 deletions Allure.Features/Allure.Features.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.SharedSteps" Version="3.0.7" />

Expand Down
1 change: 1 addition & 0 deletions Allure.Features/allureConfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/identifiers-fix/Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json",
"allure": {
"title": "5994A3F7-AF84-46AD-9393-000BB45553CC",
"directory": "allure-results",
Expand Down
6 changes: 3 additions & 3 deletions Allure.NUnit.Examples/Allure.NUnit.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
</ItemGroup>

Expand All @@ -16,9 +16,9 @@
</ItemGroup>

<ItemGroup>
<Resource Include="allureConfig.json">
<Content Include="allureConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</Content>
<Resource Include="AllureIgnoredTest.cs" />
<None Include="./../img/Allure-Color.png" PackagePath="\">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
30 changes: 21 additions & 9 deletions Allure.NUnit.Examples/AllureStepNameInternalsTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Allure.Net.Commons;
using Allure.Net.Commons.Steps;
using NUnit.Allure.Attributes;
using NUnit.Framework;
Expand All @@ -22,10 +24,10 @@ public void TestMethod(string name, LocalTestClass request, int id)

[TestCase("", ExpectedResult = "")]
[TestCase(null, ExpectedResult = "")]
[TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "Super Mario - Allure.NUnit.Examples.AllureStepNameInternalsTest+LocalTestClass - 12345 - {3} - {100} - {-100}")]
[TestCase("{id} - {0}", ExpectedResult = "12345 - Super Mario")]
[TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - Super Mario (Allure.NUnit.Examples.AllureStepNameInternalsTest+LocalTestClass)")]
[TestCase("{id} - {request.TestField} - {request.TestProp}", ExpectedResult = "12345 - FieldValue - PropValue")]
[TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "\"Super Mario\" - {\"TestField\":\"FieldValue\",\"TestProp\":\"PropValue\"} - 12345 - {3} - {100} - {-100}")]
[TestCase("{id} - {0}", ExpectedResult = "12345 - \"Super Mario\"")]
[TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - \"Super Mario\" ({\"TestField\":\"FieldValue\",\"TestProp\":\"PropValue\"})")]
[TestCase("{id} - {request.TestField} - {request.TestProp}", ExpectedResult = "12345 - \"FieldValue\" - \"PropValue\"")]
[TestCase("{notExistingParameter} - {request.NotExistingField}", ExpectedResult = "{notExistingParameter} - {request.NotExistingField}")]
public string ApplyValues_Test(string stepNamePattern)
{
Expand All @@ -41,14 +43,19 @@ public string ApplyValues_Test(string stepNamePattern)
12345, // id = {2}
};

return AllureStepParameterHelper.GetStepName(stepNamePattern, methodBase, arguments);
return AllureStepParameterHelper.GetStepName(
stepNamePattern,
methodBase,
arguments,
new Dictionary<Type, ITypeFormatter>()
);
}

[TestCase("", ExpectedResult = "")]
[TestCase(null, ExpectedResult = "")]
[TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "Super Mario - null - 12345 - {3} - {100} - {-100}")]
[TestCase("{id} - {0}", ExpectedResult = "12345 - Super Mario")]
[TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - Super Mario (null)")]
[TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "\"Super Mario\" - null - 12345 - {3} - {100} - {-100}")]
[TestCase("{id} - {0}", ExpectedResult = "12345 - \"Super Mario\"")]
[TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - \"Super Mario\" (null)")]
[TestCase("{id} - {request.TestField} - {request.TestProp}", ExpectedResult = "12345 - {request.TestField} - {request.TestProp}")]
[TestCase("{notExistingParameter} - {request.NotExistingField}", ExpectedResult = "{notExistingParameter} - {request.NotExistingField}")]
public string ApplyNullValues_Test(string stepNamePattern)
Expand All @@ -61,7 +68,12 @@ public string ApplyNullValues_Test(string stepNamePattern)
12345, // id = {2}
};

return AllureStepParameterHelper.GetStepName(stepNamePattern, methodBase, arguments);
return AllureStepParameterHelper.GetStepName(
stepNamePattern,
methodBase,
arguments,
new Dictionary<Type, ITypeFormatter>()
);
}
}
}
1 change: 1 addition & 0 deletions Allure.NUnit.Examples/allureConfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/identifiers-fix/Allure.NUnit/Schemas/allureConfig.schema.json",
"allure": {
"directory": "allure-results",
"links": [
Expand Down
74 changes: 41 additions & 33 deletions Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Allure.Net.Commons;
using NUnit.Allure.Core;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using TestResult = Allure.Net.Commons.TestResult;

#nullable enable

namespace NUnit.Allure.Attributes
{
[AttributeUsage(AttributeTargets.Class)]
public class AllureDisplayIgnoredAttribute : NUnitAttribute, ITestAction
{
private readonly string _suiteName;
private readonly string? _suiteName = null;

public AllureDisplayIgnoredAttribute(){}

[Obsolete("Allure attributes are now supported for ignored tests. Use them instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public AllureDisplayIgnoredAttribute(string suiteNameForIgnoredTests = "Ignored")
{
_suiteName = suiteNameForIgnoredTests;
Expand All @@ -40,38 +48,7 @@ public void AfterTest(ITest suite)
);
foreach (var test in ignoredTests)
{
AllureLifecycle.Instance.UpdateTestContainer(
t => t.children.Add(test.Id)
);

var reason = test.Properties.Get(
PropertyNames.SkipReason
).ToString();

var ignoredTestResult = new TestResult
{
uuid = test.Id,
name = test.Name,
fullName = test.FullName,
status = Status.skipped,
statusDetails = new StatusDetails
{
message = test.Name
},
labels = new List<Label>
{
Label.Suite(_suiteName),
Label.SubSuite(reason),
Label.Thread(),
Label.Host(),
Label.TestClass(test.ClassName),
Label.TestMethod(test.MethodName),
Label.Package(test.ClassName)
}
};
AllureLifecycle.Instance.StartTestCase(ignoredTestResult);
AllureLifecycle.Instance.StopTestCase();
AllureLifecycle.Instance.WriteTestCase();
this.EmitResultForIgnoredTest(test);
}

AllureLifecycle.Instance.StopTestContainer();
Expand All @@ -85,5 +62,36 @@ private static IEnumerable<ITest> GetAllTests(ITest test)
{
return test.Tests.Concat(test.Tests.SelectMany(GetAllTests));
}

void EmitResultForIgnoredTest(ITest test)
{
AllureLifecycle.Instance.UpdateTestContainer(
t => t.children.Add(test.Id)
);

var reason = test.Properties.Get(
PropertyNames.SkipReason
)?.ToString() ?? "";

var ignoredTestResult = AllureNUnitHelper.CreateTestResult(test);
ignoredTestResult.status = Status.skipped;
ignoredTestResult.statusDetails = new() { message = test.Name };
this.ApplyLegacySuiteLabels(ignoredTestResult, reason);
AllureLifecycle.Instance.StartTestCase(ignoredTestResult);
AllureLifecycle.Instance.StopTestCase();
AllureLifecycle.Instance.WriteTestCase();
}

void ApplyLegacySuiteLabels(TestResult testResult, string reason)
{
if (!string.IsNullOrWhiteSpace(this._suiteName))
{
testResult.labels.AddRange(new[]
{
Label.Suite(this._suiteName),
Label.SubSuite(reason)
});
}
}
}
}
Loading
Loading