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

Allure.NUnit: fix output attachment #306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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