Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Platform overwriting/removing user console output #4425

Open
thomhurst opened this issue Dec 21, 2024 · 5 comments
Open

Testing Platform overwriting/removing user console output #4425

thomhurst opened this issue Dec 21, 2024 · 5 comments
Labels
Area: Terminal reporter Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library

Comments

@thomhurst
Copy link
Contributor

Using TUnit, I created this simple test suite:

public class Tests
{
    [Before(TestSession)]
    public static async Task BeforeTestSession()
    {
        Console.WriteLine($"BeforeTestSession started at {DateTime.Now}");
        await Task.Delay(TimeSpan.FromSeconds(5));
        Console.WriteLine($"BeforeTestSession ended at {DateTime.Now}");
    }
    
    [Before(Assembly)]
    public static async Task BeforeAssembly()
    {
        Console.WriteLine($"BeforeAssembly started at {DateTime.Now}");
        await Task.Delay(TimeSpan.FromSeconds(5));
        Console.WriteLine($"BeforeAssembly ended at {DateTime.Now}");
    }
    
    [Test]
    public void Test1()
    {
        Console.WriteLine($"Executing Test at {DateTime.Now}");
    }
}

If you just do a dotnet run on the CLI, you'll have to be quick, but when it starts to show "BeforeAssembly started", you'll see it render really quickly, but then it'll be removed and overwritten by the rendering of the [✓0/x0/↓0] ConsoleApp5.dll (net9.0|x64).

I guess this is related to the new interactive output and showing running tests etc. But overwriting user output means they may lose visibility of important information.

@Evangelink
Copy link
Member

I'm off for now so just dumping my thoughts for when I return. We need to try if the behavior is the same when using IOutput to display messages.

@Youssef1313 Youssef1313 added Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library Area: Terminal reporter and removed Needs: Triage 🔍 labels Jan 9, 2025
@Evangelink
Copy link
Member

I won't be able to investigate more right now but dumping more info of trying to repro:

Image

The before and after on assembly are not displayed at all while the test session is.

@Evangelink
Copy link
Member

@nohwnd What's your opinion and recommendations here?

@thomhurst
Copy link
Contributor Author

The before and after on assembly are not displayed at all while the test session is.

From what I saw the Before assembly happens really quickly, but then immediately after TUnit will pick up the first test and send a test node update with InProgressState, which is probably causing the output terminal to update and re-render.

@nohwnd
Copy link
Member

nohwnd commented Jan 9, 2025

This is bound to happen when the progress is enabled, and we write to the screen from a different place, e.g from the test directly without capturing the output.

There is no way around unless we substitute the Console.Out with one that is respecting the lock we have in progress reporting.

#3491

Similarly this can happen when we run in child process and parent process (testhost controller writes to the screen).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Terminal reporter Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library
Projects
None yet
Development

No branches or pull requests

4 participants