Skip to content

Commit

Permalink
Replace allure-xunit's custom attributes with runner reporter (fixes #…
Browse files Browse the repository at this point in the history
…344) (#366)

* Add support for native xunit attributes

* Fix AllureXunitTheoryAttribute base class

* Fix missing theories

* Fix missing parameters and fixture duplication for some tests

* Add support for static test functions

* Update xunit examples. Obsolete allure-xunit attributes

* Update message sink to match new steps implementation

* Remove irrelevant log method from runner

* Bump harmony to 2.3-prerelease.2. Warn if no args reported

Change Lib.Harmony dependency to 2.3-prerelease.2 for .net 7 support.
Add warning if the patch via harmony didn't work for theory args and
args aren't reported on the testcase level.

* Fix reference to lib.harmony to be listed by dotnet

* Factor out allure-related code. Tidying up obsolescence

  - Allure-xunit's code that creates, updates, starts, stops and writes
    allure objects is factored out from AllureMessageSink to
    AllureXunitHelper .
  - Removal of AllureXunitHelper's public methods was reverted. The
    methods are marked as obsolete.
  - Add missing await to an allure-xunit example to suppress the
    compilation warning.
  - Mark obsoleted allure-xunit attributes as non-browsable to prevent
    them from appearing in IDE's suggestions.

* Add deprecation info and known issues to allure-xunit README

* Fix issue links in allure-xunit readme

* Fix obsolescence message for AllureXunitHelper's public methods
  • Loading branch information
delatrie authored Jul 6, 2023
1 parent 7823d89 commit 4a55fce
Show file tree
Hide file tree
Showing 18 changed files with 736 additions and 441 deletions.
25 changes: 12 additions & 13 deletions Allure.XUnit.Examples/ExampleParameterisedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,36 @@ namespace Allure.XUnit.Examples
{
public class ExampleParameterisedTests
{

public ExampleParameterisedTests()
{
Environment.CurrentDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
}

[AllureXunitTheory]
[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test MemberData")]
[MemberData(nameof(TestDataGenerators.Data), MemberType = typeof(TestDataGenerators))]
public void TestTheoryWithMemberDataProperty(int value1, int value2, int expected)
{
var result = value1 + value2;

Assert.Equal(expected, result);
}
[AllureXunitTheory]

[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test ClassData")]
[ClassData(typeof(TestClassData))]
public void TestTheoryWithClassData(int value1, int value2, int expected)
{
var result = value1 + value2;

Assert.Equal(expected, result);
}
[AllureXunitTheory]

[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test InlineData")]
Expand All @@ -49,8 +48,8 @@ public void TestTheory(int a, int b)
{
Assert.Equal(a, b);
}
[AllureXunitTheory]

[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test MemberData with Custom Reference Type")]
Expand All @@ -60,8 +59,8 @@ public void TestTheoryWithMemberData(MyTestClass a, MyTestClass b)
{
Assert.Equal(a.Test, b.Test);
}
[AllureXunitTheory]

[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test test MemberData with random data")]
Expand All @@ -73,7 +72,7 @@ public void TestTheoryWithMemberDataThatReturnsRandomData(int value1, int value2
Assert.Equal(expected, result);
}

[AllureXunitTheory]
[Theory]
[AllureParentSuite("AllTests")]
[AllureSuite("Test AllureXunitTheory")]
[AllureSubSuite("Test test with generic arguments")]
Expand Down
12 changes: 6 additions & 6 deletions Allure.XUnit.Examples/ExampleStepAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ExampleStepAttributes()
NestedStepReturningString("Second");
}

[AllureXunit]
[Fact]
public void Test()
{
WriteHelloStep(42, 4242, "secret");
Expand All @@ -25,21 +25,21 @@ public void Test()
SomeStep();
}

[AllureXunit]
[Fact]
public void TestSecond()
{
SomeStep();
}

[AllureXunit(DisplayName = "This test should be red")]
[Fact(DisplayName = "This test should be red")]
public void TestFailed()
{
SomeStep();
FailingStep();
SomeStep();
}
[AllureXunit(DisplayName = "This test should be yellow")]

[Fact(DisplayName = "This test should be yellow")]
public void TestBroken()
{
SomeStep();
Expand Down Expand Up @@ -84,7 +84,7 @@ private void FailingStep()
{
Assert.True(false);
}

[AllureStep("Check that everytime you call this step it will throw an exception")]
private void ExceptionStep()
{
Expand Down
16 changes: 12 additions & 4 deletions Allure.XUnit.Examples/ExampleSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
using Allure.Xunit;
using Allure.Xunit.Attributes;
using Xunit;
using Xunit.Abstractions;

namespace Allure.XUnit.Examples;

[Obsolete("See ExampleStepAttributes")]
[AllureSuite("ExampleSteps (Obsolete)")]
public class ExampleSteps : IAsyncLifetime
{
ITestOutputHelper output;

public ExampleSteps(ITestOutputHelper output)
{
this.output = output;
}

public Task InitializeAsync()
{
using (new AllureBefore("Initialization"))
Expand All @@ -27,14 +35,14 @@ public Task DisposeAsync()
return Task.CompletedTask;
}

[AllureXunit(Skip = "ExampleSteps is obsolete")]
[Fact(Skip = "ExampleSteps is obsolete")]
public async Task TestParameters()
{
WriteHello(42, 4242, "secret");
await AddAttachment();
}

[AllureXunit(Skip = "ExampleSteps is obsolete")]
[Fact(Skip = "ExampleSteps is obsolete")]
public void TestFail()
{
using (new AllureStep("Test Fail"))
Expand All @@ -46,11 +54,11 @@ public void TestFail()
}
}

private static void WriteHello(int parameter, int renameMe, string password)
private void WriteHello(int parameter, int renameMe, string password)
{
using (new AllureStep("Write Hello").SetParameter(parameter).SetParameter("value", renameMe))
{
AllureMessageBus.TestOutputHelper.Value.WriteLine("Hello from Step");
this.output.WriteLine("Hello from Step");
}
}

Expand Down
19 changes: 13 additions & 6 deletions Allure.XUnit.Examples/ExampleUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public ExampleUnitTests()
{
Environment.CurrentDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
}
[AllureXunit(DisplayName = "Test that 1 is not equals 1")]

[Fact(DisplayName = "Test that 1 is not equals 1")]
[AllureDescription("My long test description; Lorem ipsum dolor sit amet.")]
[AllureFeature("qwerty", "123")]
[AllureTag("TAG-1")]
Expand All @@ -41,28 +41,35 @@ public void Test1()
}


[AllureXunit(DisplayName = "Test that 1 is equals 1")]
[Fact(DisplayName = "Test that 1 is equals 1")]
[AllureSeverity(SeverityLevel.critical)]
public async Task Test2()
{
await Task.Delay(0);
Assert.True(1 == 1);
Attachments.File("allureConfig", @"./allureConfig.json");
}

[AllureXunit(DisplayName = "Another Test")]
[Fact(DisplayName = "Another Test")]
public void Test3()
{
Assert.Empty(new List<int>() {1, 2, 3});
}

[AllureXunit]
[Fact]
[AllureTag(new[] {"TAG-8", "TAG-9", "TAG-10"}, true)]
public void TestMultipleTagsWithOverwrite()
{
Assert.True(!false);
}

[AllureXunit(DisplayName = "Test mapped to existing test case #1 in allure")]
[Fact]
public static void StaticTest()
{
Assert.True(true);
}

[Fact(DisplayName = "Test mapped to existing test case #1 in allure")]
[AllureId("1")]
public void TestAllureIdMapping()
{
Expand Down
2 changes: 2 additions & 0 deletions Allure.XUnit/Allure.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.3.0-prerelease.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="xunit.runner.utility" Version="2.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
54 changes: 0 additions & 54 deletions Allure.XUnit/AllureMessageBus.cs

This file was deleted.

Loading

0 comments on commit 4a55fce

Please sign in to comment.