Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions TUnit.Engine/CommandLineProviders/VerbosityCommandProvider.cs

This file was deleted.

5 changes: 1 addition & 4 deletions TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public static void AddTUnit(this ITestApplicationBuilder testApplicationBuilder)
testApplicationBuilder.CommandLine.AddProvider(() => new ParallelismStrategyCommandProvider(extension));
testApplicationBuilder.CommandLine.AddProvider(() => new AdaptiveMetricsCommandProvider(extension));

// Unified verbosity control (replaces HideTestOutput, DisableLogo)
testApplicationBuilder.CommandLine.AddProvider(() => new VerbosityCommandProvider(extension));

// Keep detailed stacktrace option for backward compatibility
// Keep detailed stacktrace option for backward compatibility
testApplicationBuilder.CommandLine.AddProvider(() => new DetailedStacktraceCommandProvider(extension));

// GitHub reporter configuration
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Engine/Framework/TUnitServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public TUnitServiceProvider(IExtension extension,

TestContext.Configuration = new ConfigurationAdapter(configuration);

VerbosityService = Register(new VerbosityService(CommandLineOptions));
VerbosityService = Register(new VerbosityService(CommandLineOptions, frameworkServiceProvider));
DiscoveryDiagnostics.Initialize(VerbosityService);

var logLevelProvider = Register(new LogLevelProvider(CommandLineOptions));
Expand Down
56 changes: 0 additions & 56 deletions TUnit.Engine/Logging/TUnitVerbosity.cs

This file was deleted.

101 changes: 64 additions & 37 deletions TUnit.Engine/Services/VerbosityService.cs
Original file line number Diff line number Diff line change
@@ -1,98 +1,125 @@
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Services;
using TUnit.Engine.CommandLineProviders;
using TUnit.Engine.Helpers;
using TUnit.Engine.Logging;
using LogLevel = TUnit.Core.Logging.LogLevel;

#pragma warning disable TPEXP

namespace TUnit.Engine.Services;

/// <summary>
/// Centralized service for managing TUnit output verbosity and diagnostic settings
/// Centralized service for managing TUnit output and diagnostic settings
/// </summary>
public sealed class VerbosityService
{
private readonly TUnitVerbosity _verbosity;
private readonly bool _isDetailedOutput;
private readonly LogLevel _logLevel;

public VerbosityService(ICommandLineOptions commandLineOptions)
public VerbosityService(ICommandLineOptions commandLineOptions, IServiceProvider serviceProvider)
{
_verbosity = GetVerbosityFromCommandLine(commandLineOptions);
_isDetailedOutput = GetOutputLevel(commandLineOptions, serviceProvider);
_logLevel = GetLogLevel(commandLineOptions);
}

/// <summary>
/// Current verbosity level
/// Whether to show detailed stack traces (enabled with Debug/Trace log level)
/// </summary>
public TUnitVerbosity CurrentVerbosity => _verbosity;
public bool ShowDetailedStackTrace => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to show detailed stack traces (Verbose+ levels)
/// Whether to hide real-time test output (hidden with --output Normal)
/// </summary>
public bool ShowDetailedStackTrace => _verbosity.Includes(TUnitVerbosity.Verbose);
public bool HideTestOutput => !_isDetailedOutput;

/// <summary>
/// Whether to hide test output (Minimal level only)
/// Whether to show the TUnit logo
/// </summary>
public bool HideTestOutput => _verbosity == TUnitVerbosity.Minimal;
public bool ShowLogo => true;

/// <summary>
/// Whether to show the TUnit logo (Normal+ levels)
/// Whether to enable discovery diagnostics (enabled with Debug/Trace log level)
/// </summary>
public bool ShowLogo => _verbosity.Includes(TUnitVerbosity.Normal);
public bool EnableDiscoveryDiagnostics => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to enable discovery diagnostics (Debug level only)
/// Whether to enable verbose source generator diagnostics (enabled with Debug/Trace log level)
/// </summary>
public bool EnableDiscoveryDiagnostics => _verbosity.Includes(TUnitVerbosity.Debug);
public bool EnableVerboseSourceGeneratorDiagnostics => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to enable verbose source generator diagnostics (Debug level only)
/// Whether to show execution timing details (enabled with Debug/Trace log level)
/// </summary>
public bool EnableVerboseSourceGeneratorDiagnostics => _verbosity.Includes(TUnitVerbosity.Debug);
public bool ShowExecutionTiming => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to show execution timing details (Verbose+ levels)
/// Whether to show parallel execution details (enabled with Debug/Trace log level)
/// </summary>
public bool ShowExecutionTiming => _verbosity.Includes(TUnitVerbosity.Verbose);
public bool ShowParallelExecutionDetails => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to show parallel execution details (Debug level only)
/// Whether to show test discovery progress (enabled with Debug/Trace log level)
/// </summary>
public bool ShowParallelExecutionDetails => _verbosity.Includes(TUnitVerbosity.Debug);
public bool ShowDiscoveryProgress => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to show test discovery progress (Verbose+ levels)
/// Whether to show memory and resource usage (enabled with Debug/Trace log level)
/// </summary>
public bool ShowDiscoveryProgress => _verbosity.Includes(TUnitVerbosity.Verbose);
public bool ShowResourceUsage => _logLevel <= LogLevel.Debug;

/// <summary>
/// Whether to show memory and resource usage (Debug level only)
/// </summary>
public bool ShowResourceUsage => _verbosity.Includes(TUnitVerbosity.Debug);

/// <summary>
/// Creates a summary of current verbosity settings
/// Creates a summary of current output and diagnostic settings
/// </summary>
public string CreateVerbositySummary()
{
return $"Verbosity: {_verbosity.ToDisplayString()} " +
var outputMode = _isDetailedOutput ? "Detailed" : "Normal";
return $"Output: {outputMode}, Log Level: {_logLevel} " +
$"(Stack traces: {ShowDetailedStackTrace}, " +
$"Logo: {ShowLogo}, " +
$"Discovery diagnostics: {EnableDiscoveryDiagnostics})";
}

// Use centralized environment variable cache

private static TUnitVerbosity GetVerbosityFromCommandLine(ICommandLineOptions commandLineOptions)

private static bool GetOutputLevel(ICommandLineOptions commandLineOptions, IServiceProvider serviceProvider)
{
// Check for --output flag (Microsoft.Testing.Platform extension)
if (commandLineOptions.TryGetOptionArgumentList("output", out var args) && args.Length > 0)
{
return args[0].Equals("Detailed", StringComparison.OrdinalIgnoreCase);
}

// Smart defaults: Normal for console (buffered output), Detailed for IDE (real-time output)
return !IsConsoleEnvironment(serviceProvider);
}

private static LogLevel GetLogLevel(ICommandLineOptions commandLineOptions)
{
if (commandLineOptions.TryGetOptionArgumentList(VerbosityCommandProvider.Verbosity, out var args) && args.Length > 0)
// Check for --log-level flag
if (commandLineOptions.TryGetOptionArgumentList(LogLevelCommandProvider.LogLevelOption, out var args) && args.Length > 0)
{
return VerbosityCommandProvider.ParseVerbosity(args);
return LogLevelCommandProvider.ParseLogLevel(args);
}

// Check cached legacy environment variable for backwards compatibility
if (EnvironmentVariableCache.Get("TUNIT_DISCOVERY_DIAGNOSTICS") == "1")
{
return TUnitVerbosity.Debug;
return LogLevel.Debug;
}

return TUnitVerbosity.Normal;
return LogLevel.Information;
}

private static bool IsConsoleEnvironment(IServiceProvider serviceProvider)
{
try
{
var clientInfo = serviceProvider.GetClientInfo();
return clientInfo.Id.Contains("console", StringComparison.InvariantCultureIgnoreCase);
}
catch
{
// If we can't determine, default to console behavior
return true;
}
}
}
1 change: 1 addition & 0 deletions TUnit.Engine/TUnitMessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using TUnit.Engine.CommandLineProviders;
using TUnit.Engine.Exceptions;
using TUnit.Engine.Extensions;
using TUnit.Engine.Logging;
using TUnit.Engine.Services;

#pragma warning disable TPEXP
Expand Down
19 changes: 11 additions & 8 deletions docs/docs/reference/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ Please note that for the coverage and trx report, you need to install [additiona
List available tests.

--log-level
Minimum log level for test output.
The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', 'Critical', and 'None'.
Default is 'Information'.
Controls framework logging and diagnostic features.
The available values are:
- 'Trace' or 'Debug': Enable detailed stack traces, discovery diagnostics, timing details
- 'Information' (default): Normal framework behavior
- 'Warning', 'Error', 'Critical', or 'None': Minimal framework output

--minimum-expected-tests
Specifies the minimum number of tests that are expected to run.
Expand Down Expand Up @@ -78,9 +80,6 @@ Please note that for the coverage and trx report, you need to install [additiona
--fail-fast
Cancel the test run after the first test failure

--hide-test-output
Hide Test Output

--maximum-parallel-tests
Maximum Parallel Tests

Expand All @@ -91,8 +90,12 @@ Please note that for the coverage and trx report, you need to install [additiona
Disable reporting progress to screen.

--output
Output verbosity when reporting tests.
Valid values are 'Normal', 'Detailed'. Default is 'Normal'.
Controls test result detail level AND real-time console output buffering.
- 'Normal': Show failures only + buffer test output (no real-time spam)
- 'Detailed': Show all tests + real-time test output

Smart defaults: 'Normal' for console environments, 'Detailed' for IDE environments.
This prevents console spam while keeping IDEs responsive (each test has its own output window).

--reflection
Enable reflection mode for test discovery and execution (defaults to source generation mode)
Expand Down
Loading