Skip to content

Commit

Permalink
Fix missing output attachments in NUnit adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
undron authored Dec 22, 2022
1 parent f291a45 commit 2b55f5c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Allure.NUnit.Examples/OutputTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.IO;
using System.Linq;
using Allure.Net.Commons;
using NUnit.Allure.Attributes;
using NUnit.Framework;

namespace Allure.NUnit.Examples
{
[AllureSuite("Tests - Output")]
public class OutputTest : BaseTest
{
private const string text = "This should go to console output attachment";

[Test]
[Order(1)]
public void WriteOutputTest()
{
Console.WriteLine(text);
}

[Test]
[Order(2)]
public void OutputLogShouldExist()
{
var resultsDir = AllureLifecycle.Instance.ResultsDirectory;
var attachmentFiles = Directory.EnumerateFiles(resultsDir, "*.txt");

Assert.That(attachmentFiles.Any(file => File.ReadAllText(file).Contains(text)));
}
}
}

9 changes: 9 additions & 0 deletions Allure.NUnit/Core/AllureNUnitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private TestFixture GetTestFixture(ITest test)
internal void StopTestCase()
{
UpdateTestDataFromAttributes();
AddConsoleOutputAttachment();

for (var i = 0; i < _test.Arguments.Length; i++)
{
AllureLifecycle.UpdateTestCase(x => x.parameters.Add(new Parameter
Expand Down Expand Up @@ -176,6 +178,13 @@ private void UpdateTestDataFromAttributes()
});
}

private void AddConsoleOutputAttachment()
{
var output = TestExecutionContext.CurrentContext.CurrentResult.Output;
AllureLifecycle.AddAttachment("Console Output", "text/plain",
Encoding.UTF8.GetBytes(output), ".txt");
}

private IEnumerable<string> GetTestProperties(string name)
{
var list = new List<string>();
Expand Down

0 comments on commit 2b55f5c

Please sign in to comment.