Skip to content

Commit

Permalink
Support allureId attribute to permanent mapping result to existing te…
Browse files Browse the repository at this point in the history
…st case (#26)

* Support allureId attribute to permanent mapping result to existing test case

* Support allureId attribute to permanent mapping result to existing test case: rename to AllureId from AllureAllureId

Co-authored-by: Danila Polevshchikov <danila.polevshchikov@go-springtime.com>
  • Loading branch information
sphinxy and Danila Polevshchikov authored Jun 9, 2022
1 parent f8a685a commit 2aa6c96
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Allure.XUnit supports .NET Core 2.0 and later.
* AllureLink
* AllureEpic
* AllureLabel
* AllureId
* AllureXunitTheory - attribute for display parametrized tests. Use ```InlineData```, ```MemberData```, ```ClassData```,
XUnit attributes for pass parameters.

Expand All @@ -48,6 +49,7 @@ Most of the attributes can be used both on methods and classes.
| AllureEpic | x | x |
| AllureLabel | x | x |
| AllureXunitTheory | x | |
| AllureId | x | |

To override attribute value you can use `overwrite` param in attribute definition.
In other case multiple values will be written in test results.
Expand Down
5 changes: 4 additions & 1 deletion src/Allure.XUnit.Examples/Allure.XUnit.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/Allure.XUnit.Examples/ExampleUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ public void TestMultipleTagsWithOverwrite()
{
Assert.True(!false);
}

[AllureXunit(DisplayName = "Test mapped to existing test case #1 in allure")]
[AllureId("1")]
public void TestAllureIdMapping()
{
Assert.True(true);
}
}
}
4 changes: 2 additions & 2 deletions src/Allure.XUnit/Allure.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Title>Allure.XUnit</Title>
<Authors>Shumakov Ivan</Authors>
<Description>Allure.XUnit</Description>
<PackageProjectUrl>https://github.com/TinkoffCreditSystems/Allure.XUnit</PackageProjectUrl>
<RepositoryUrl>https://github.com/TinkoffCreditSystems/Allure.XUnit</RepositoryUrl>
<PackageProjectUrl>https://github.com/Tinkoff/Allure.XUnit</PackageProjectUrl>
<RepositoryUrl>https://github.com/Tinkoff/Allure.XUnit</RepositoryUrl>
<PackageTags>allure; xunit;</PackageTags>
<LangVersion>9</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Allure.XUnit/AllureXunitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ private static void UpdateTestDataFromAttributes(TestResult testResult, ITestCas
testResult.description = descriptionAttribute.Description;
break;


case AllureIdAttribute allureIdAttribute:
var allureIdLabel = new Label {name = "as_id", value = allureIdAttribute.AllureId};
testResult.labels.AddDistinct(allureIdLabel, false);
break;

case AllureLabelAttribute labelAttribute:
var label = new Label()
{
Expand Down
19 changes: 19 additions & 0 deletions src/Allure.XUnit/Attributes/AllureIdAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Allure.Xunit.Attributes
{
/// <summary>
/// Internal AllureId of test case, used to permanent mapping result to existing automatic test case. NB: don't confuse with "test case id" aka id for external TMS system.
/// https://docs.qameta.io/allure-testops/ecosystem/intellij-plugin/#link-tests-in-ide-to-tests-cases-in-allure-testops-via-allureid
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class AllureIdAttribute : Attribute, IAllureInfo
{
public AllureIdAttribute(string allureId)
{
AllureId = allureId;
}

public string AllureId { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.145" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 2aa6c96

Please sign in to comment.