TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

Only output test logs when test fails or when using `--output Detailed`

Open AlexandreBossard opened this issue 8 months ago • 0 comments

Pretty much the title 😸

with the following code

[Test]
public async Task Test1()
{
    var context = TestContext.Current!;
    Console.WriteLine("This is a console write line");
    context.GetDefaultLogger().LogInformation("This is an info");
    await context.GetDefaultLogger().LogErrorAsync("This is an error");
     // Assert.Fail("fail");
}

outputs:

dotnet run --project test/Functional.Tests/ -- --disable-logo --treenode-filter '/*/*/*/Test1' --no-progress
TUnit v0.19.82.0 | 64-bit | Garuda Linux | linux-x64 | .NET 9.0.5 | Microsoft Testing Platform v1.6.3
This is a console write line
Information: This is an info


Error: This is an error



Test run summary: Passed! - test/Functional.Tests/bin/Debug/net9.0/Functional.Tests.dll (net9.0|x64)
  total: 1
  failed: 0
  succeeded: 1
  skipped: 0
  duration: 301ms

I can see my logs, and I don't want to, as my test passes.

Also if I add --output Detailed

dotnet run --project test/Functional.Tests/ -- --disable-logo --treenode-filter '/*/*/*/Test1' --no-progress --output Detailed
TUnit v0.19.82.0 | 64-bit | Garuda Linux | linux-x64 | .NET 9.0.5 | Microsoft Testing Platform v1.6.3
This is a console write line
Information: This is an info


Error: This is an error


passed Test1 (105ms)
  Standard output
    This is a console write line
    Information: This is an info
  Error output
    Error: This is an error

Test run summary: Passed! - test/Functional.Tests/bin/Debug/net9.0/Functional.Tests.dll (net9.0|x64)
  total: 1
  failed: 0
  succeeded: 1
  skipped: 0
  duration: 276ms

you can see the output is repeated, same if the test fails.

In that simple example, it looks fine, but when you have a lot of tests, it completely clog up the tests outputs.

I think the "immediate" output of the tests should not be printed unless asked with some --output unbuffered. The summary should only be printed with the Detailed option and should only be printed when the test fails otherwise (Normal options)

What do you think ?

AlexandreBossard avatar May 26 '25 16:05 AlexandreBossard