Skip to content

Standard test output is not logged to allure for failed tests, but lo… #32

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
33 changes: 31 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ on:
push:
pull_request:

permissions:
checks: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
Expand All @@ -24,4 +27,30 @@ jobs:
if: github.ref == 'refs/heads/master'
run: dotnet nuget push src/*/bin/Release/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.STEP_EXTENSIONS_NUGET_API }}
NUGET_API_KEY: ${{ secrets.STEP_EXTENSIONS_NUGET_API }}

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Build
run: dotnet build src
- name: Test
run: dotnet test src --no-build --verbosity normal --logger=trx
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
trx_files: "**/*.trx"
comment_mode: off
- name: Upload allure results
uses: actions/upload-artifact@v3
if: always()
with:
name: allure-results
path: src/**/allure-results/*.json
1 change: 1 addition & 0 deletions src/Allure.XUnit.Examples/Allure.XUnit.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net6.0</TargetFramework>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions src/Allure.XUnit.Examples/ExampleUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Allure.Xunit;
using Allure.Xunit.Attributes;
using Xunit;
using Xunit.Abstractions;

namespace Allure.XUnit.Examples
{
Expand All @@ -20,15 +21,18 @@ namespace Allure.XUnit.Examples
[AllureLink("Tinkoff", "https://tinkoff.ru")]
public class ExampleUnitTests : IDisposable
{
private readonly ITestOutputHelper _testOutputHelper;

public void Dispose()
{
}

public ExampleUnitTests()
public ExampleUnitTests(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
Environment.CurrentDirectory = Path.GetDirectoryName(GetType().Assembly.Location);
}

[AllureXunit(DisplayName = "Test that 1 is not equals 1")]
[AllureDescription("My long test description; Lorem ipsum dolor sit amet.")]
[AllureFeature("qwerty", "123")]
Expand All @@ -52,7 +56,7 @@ public async Task Test2()
[AllureXunit(DisplayName = "Another Test")]
public void Test3()
{
Assert.Empty(new List<int>() {1, 2, 3});
Assert.Empty(new List<int>() {1,2,3});
}

[AllureXunit]
Expand All @@ -63,10 +67,23 @@ public void TestMultipleTagsWithOverwrite()
}

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

[AllureXunit(DisplayName = "Test output is logged for success test")]
public void TestStandardOutputSavedToAllureForSuccessTest()
{
_testOutputHelper.WriteLine("This output of success test should be visible in IDE and logged in allure-result/*result.json");
Assert.True(true);
}

[AllureXunit(DisplayName = "Test output is logged for failed test")]
public void TestStandardOutputSavedToAllureForFailedTest()
{
_testOutputHelper.WriteLine("This output of failed test should be visible in IDE and in logged allure-result/*result.json");
Assert.False(true, "This failed assert is logged too along with previous output");
}
}
}
1 change: 1 addition & 0 deletions src/Allure.XUnit/Allure.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<RepositoryUrl>https://github.com/Tinkoff/Allure.XUnit</RepositoryUrl>
<PackageTags>allure; xunit;</PackageTags>
<LangVersion>9</LangVersion>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Allure.XUnit/AllureXunitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static void MarkTestCaseAsFailed(ITestFailed testFailed)

var statusDetails = testResults.TestResult.statusDetails ??= new();
statusDetails.trace = string.Join('\n', testFailed.StackTraces);
statusDetails.message = string.Join('\n', testFailed.Messages);
var mergedMessagedAndOutput = testFailed.Messages.Append(testFailed.Output);
statusDetails.message = string.Join('\n', mergedMessagedAndOutput);
testResults.TestResult.status = Status.failed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
Expand Down