Skip to content

Instantly share code, notes, and snippets.

@Stewartarmbrecht
Created September 10, 2015 16:10
Show Gist options
  • Save Stewartarmbrecht/ba079cf6dc42a46816ac to your computer and use it in GitHub Desktop.
Save Stewartarmbrecht/ba079cf6dc42a46816ac to your computer and use it in GitHub Desktop.
xUnit Concurrency Problem with ITestOutputHelper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace xBDD.Test.Features.RunTests
{
public class xUnitTestOutputConcurrencyIssue
{
private readonly ITestOutputHelper outputWriter;
public xUnitTestOutputConcurrencyIssue(ITestOutputHelper output)
{
this.outputWriter = output;
}
[Fact]
public void ShouldBeAsync()
{
Task.Run(() => {
System.Threading.Thread.Sleep(5);
outputWriter.WriteLine("I am the async write!");
});
}
[Fact]
public void Sync1()
{
System.Threading.Thread.Sleep(5);
outputWriter.WriteLine("I am the sync test.");
}
[Fact]
public void Sync2()
{
System.Threading.Thread.Sleep(5);
outputWriter.WriteLine("I am the sync test.");
}
[Fact]
public void Sync3()
{
System.Threading.Thread.Sleep(5);
outputWriter.WriteLine("I am the sync test.");
}
[Fact]
public void Sync4()
{
System.Threading.Thread.Sleep(5);
outputWriter.WriteLine("I am the sync test.");
}
}
}
Output:
<collection total="5" passed="5" failed="0" skipped="0" name="Test collection for xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" time="0.024">
<test name="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue.Sync3" type="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" method="Sync3" time="0.0061421" result="Pass">
<output><![CDATA[I am the sync test.
]]></output>
</test>
<test name="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue.ShouldBeAsync" type="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" method="ShouldBeAsync" time="0.0002223" result="Pass" />
<test name="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue.Sync4" type="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" method="Sync4" time="0.0055084" result="Pass">
<output><![CDATA[I am the sync test.
]]></output>
</test>
<test name="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue.Sync2" type="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" method="Sync2" time="0.0058723" result="Pass">
<output><![CDATA[I am the async write!
I am the sync test.
]]></output>
</test>
<test name="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue.Sync1" type="xBDD.Test.Features.RunTests.xUnitTestOutputConcurrencyIssue" method="Sync1" time="0.0058414" result="Pass">
<output><![CDATA[I am the sync test.
]]></output>
</test>
</collection>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment