Skip to content

TestContext does not flow in async method #1965

Closed
@Suremaker

Description

@Suremaker

Example tests recreating issue:

[TestFixture]
public class TestContext_async_issue
{
    [Test]
    public async Task TestContext_Out_should_flow_with_async_execution()
    {
        var expected = TestContext.Out;
        await Task.Yield();
        Assert.AreSame(expected, TestContext.Out);
    }

    [Test]
    public async Task TestContext_CurrentContext_should_flow_with_async_execution()
    {
        var expected = TestContext.CurrentContext;
        await Task.Yield();
        Assert.AreSame(expected, TestContext.CurrentContext);
    }
}

The side effect of that behaviour is that it is not possible to use TestContext.WriteLine() after await as it causes NullReferenceException.

Tested with NUnit 3.5.0, net46 and netcoreapp1.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions