Skip to content

Console output not showing from ITestEventListener #1652

Closed
@m-kl

Description

@m-kl

Hello everyone,

I am trying to develop a simple nunit extension that writes the currently executed test fixture to the console.

private TextReader _out = Console.Out;

public void OnTestEvent(string report) {
    var document = XDocument.Parse(report);

    var rootElement = document.Root;
    if (rootElement == null || rootElement.Name != "start-suite") {
        return;
    }

    var typeAttribute = rootElement.Attribute("type");
    if (typeAttribute is not { Value: "TestFixture" }) {
        return;
    }

    var fullnameAttribute = rootElement.Attribute("fullname");
    if (fullnameAttribute == null) {
        return;
    }

    var fullname = fullnameAttribute.Value;
    _out.WriteLine($"1 Running TestFixture: {fullname}");
    _out.Flush();

    Console.WriteLine($"2 Running TestFixture: {fullname}");

    TestContext.Progress.WriteLine($"3 Running TestFixture: {fullname}");
    TestContext.Progress.Flush();

    TestContext.Out.WriteLine($"4 Running TestFixture: {fullname}");
    TestContext.Out.Flush();
}

Running a test using "dotnet test" in a hello world like environment results in one of those four output lines being printed to the console:
"1 Running TestFixture: TestService.Test.Tests"

I am wondering why only the output from the manually captures Console.Out shows up and where I might find the other outputs and whether this is an error. In our real test environment, not even the output from _out shows up, but in my opinion this doesn't look like the output channel that should be used anyway and rather like a hack.
Is there a known issue regarding the output to the TextWriters above or is there anything I need to configure additionally to find those outputs?

My NUnit Version is 4.2.2

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions