forked from redhat-developer/dotnet-bunny
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for producing junit-compatible results
- Loading branch information
Showing
6 changed files
with
225 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Turkey.Tests | ||
{ | ||
public class JUnitOutputTest | ||
{ | ||
[Fact] | ||
public async Task EmptyResultsProduceBasicXml() | ||
{ | ||
var resultsFile = new FileInfo(Path.GetTempFileName()); | ||
|
||
var j = new TestOutputFormats.JUnitOutput(resultsFile); | ||
await j.AfterRunningAllTestsAsync(null); | ||
var xml = File.ReadAllText(resultsFile.FullName); | ||
|
||
var expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<testsuite />"; | ||
|
||
Assert.Equal(expectedXml, xml); | ||
|
||
resultsFile.Delete(); | ||
} | ||
|
||
[Fact] | ||
public async Task SingleTestWithPassingResultProducesValidXml() | ||
{ | ||
var resultsFile = new FileInfo(Path.GetTempFileName()); | ||
|
||
var j = new TestOutputFormats.JUnitOutput(resultsFile); | ||
var result = new TestResult(TestStatus.Passed, "", ""); | ||
await j.AfterRunningTestAsync("foo", result, new TimeSpan(0)); | ||
await j.AfterRunningAllTestsAsync(null); | ||
var xml = File.ReadAllText(resultsFile.FullName); | ||
|
||
var expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<testsuite> | ||
<testcase name=""foo"" classname=""TestSuite""> | ||
<system-out></system-out> | ||
<system-err></system-err> | ||
</testcase> | ||
</testsuite>"; | ||
|
||
Assert.Equal(expectedXml, xml); | ||
|
||
resultsFile.Delete(); | ||
} | ||
|
||
[Fact] | ||
public async Task ControlCharactersInTestOutputAreNotPresentInXml() | ||
{ | ||
var resultsFile = new FileInfo(Path.GetTempFileName()); | ||
|
||
var j = new TestOutputFormats.JUnitOutput(resultsFile); | ||
var result = new TestResult(TestStatus.Passed, | ||
standardOutput: "\u0001\u0002\u0003\u0004\u0005aaa\u0006\u0007\u0008", | ||
standardError: "\u001A\u001B\u001Cbbb\u001d"); | ||
await j.AfterRunningTestAsync("foo", result, new TimeSpan(0)); | ||
await j.AfterRunningAllTestsAsync(null); | ||
var xml = File.ReadAllText(resultsFile.FullName); | ||
|
||
var expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<testsuite> | ||
<testcase name=""foo"" classname=""TestSuite""> | ||
<system-out>aaa</system-out> | ||
<system-err>bbb</system-err> | ||
</testcase> | ||
</testsuite>"; | ||
|
||
Assert.Equal(expectedXml, xml); | ||
|
||
resultsFile.Delete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Turkey | ||
{ | ||
static class IEnumerableExtensions | ||
{ | ||
public static async Task ForEachAsync<T>(this IEnumerable<T> items, Func<T, Task> task) | ||
{ | ||
foreach (T item in items) | ||
{ | ||
await task(item); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters