-
-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Problem Description
Console output (e.g., Console.WriteLine()) from test data class constructors and IAsyncInitializer.InitializeAsync() is not being captured and displayed in test results. This output disappears completely, making it difficult to debug or track progress during long-running initialization operations.
Code Example
public sealed class TestRabbitContainer : IAsyncInitializer
{
public TestRabbitContainer()
{
Console.WriteLine("Constructor called"); // This output disappears
}
public async Task InitializeAsync()
{
await _instance.StartAsync(); // Long-running operation
Console.WriteLine("Initialization complete"); // This output also disappears
}
}
// Usage in test
[ClassDataSource<TestRabbitContainer>(Shared = SharedType.PerTestSession)]
public required TestRabbitContainer TestRabbitContainer { get; init; }Root Cause Analysis
Based on codebase investigation:
-
Context Availability Issue:
StandardOutConsoleInterceptor.cs(line 14) redirects console output to:protected override TextWriter RedirectedOut => Context.Current.OutputWriter;
-
Timing Problem: Test data is constructed in
ClassDataSources.Create()method beforeTestContext.Currentis set. InTestCoordinator.cs(line 73):TestContext.Current = test.Context;
This happens AFTER class data has already been created.
-
Data Construction Flow: The
ClassDataSources.csCreate()method (lines 74-120) instantiates objects viaActivator.CreateInstance()and initializes them, but at this point there's no TestContext available yet to capture output.
Expected vs Actual Behavior
- Expected: Console output from constructors and
InitializeAsync()should be captured and displayed in test results or logs - Actual: Output disappears because there's no TestContext to write to when these methods execute
Impact
This is particularly problematic for:
- Resource-heavy initialization (Docker containers, database setup, etc.)
- Debugging initialization issues
- Tracking progress of long-running setup operations
- Understanding why initialization is taking significant time
Workaround
None currently available. Output must be captured through alternative means (e.g., custom logging to files).
Related
Originally reported in discussion #3803