Using Xunit test output helper in some tests#1362
Using Xunit test output helper in some tests#1362kfrajtak wants to merge 5 commits intodanielgerlag:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds XUnit test output helper integration to improve test feedback and logging capabilities. The changes enable tests to capture and output log entries through XUnit's test output mechanism.
- Added new
XUnitLoggerclass to bridge .NET logging with XUnit test output - Updated delay scenario test classes across different database providers to accept
ITestOutputHelperparameter - Modified the base
WorkflowTestclass to integrate the XUnit logger into the dependency injection container
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/WorkflowCore.Testing/XUnitLogger.cs | New logger implementation that outputs to XUnit test output helper |
| src/WorkflowCore.Testing/WorkflowTest.cs | Updated base test class to integrate XUnit logger and accept test output helper |
| src/WorkflowCore.Testing/WorkflowCore.Testing.csproj | Added reference to xunit.abstractions assembly |
| test/WorkflowCore.IntegrationTests/Scenarios/DelayScenario.cs | Updated constructor to accept and pass through test output helper |
| test/WorkflowCore.Tests.*/Scenarios/*DelayScenario.cs | Updated constructors across database-specific test scenarios to accept test output helper |
Comments suppressed due to low confidence (1)
src/WorkflowCore.Testing/WorkflowCore.Testing.csproj:24
- Using a hard-coded HintPath with absolute path references is fragile and will break on different machines. Consider using a PackageReference instead of a direct assembly reference for better portability and dependency management.
<HintPath>..\..\..\..\..\.nuget\packages\xunit.abstractions\2.0.3\lib\netstandard2.0\xunit.abstractions.dll</HintPath>
|
|
||
| private static string GetLogLevelString(LogLevel logLevel) | ||
| { | ||
| return logLevel.ToString().ToUpper(); |
There was a problem hiding this comment.
There's trailing whitespace after the semicolon which affects code cleanliness.
| return logLevel.ToString().ToUpper(); | |
| return logLevel.ToString().ToUpper(); |
| services.AddLogging(); | ||
| services.AddLogging(l => l.SetMinimumLevel(LogLevel.Trace)); | ||
| services.AddSingleton<ILoggerProvider>(p => new XUnitLoggerProvider(testOutputHelper)); | ||
| services.Add(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>()); |
There was a problem hiding this comment.
Explicitly registering LoggerFactory as singleton may conflict with the existing logging setup from AddLogging(). The AddLogging() method already registers ILoggerFactory, so this additional registration could cause issues.
| services.Add(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>()); | |
| // Removed explicit registration of LoggerFactory as singleton for ILoggerFactory to avoid conflict with AddLogging() |
| services.AddLogging(l => l.SetMinimumLevel(LogLevel.Trace)); | ||
| services.AddSingleton<ILoggerProvider>(p => new XUnitLoggerProvider(testOutputHelper)); | ||
| services.Add(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>()); | ||
| services.Add(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(XUnitLogger<>))); |
There was a problem hiding this comment.
Registering ILogger<> directly may interfere with the logging framework's factory pattern. The ILoggerFactory should be responsible for creating ILogger instances through its CreateLogger method.
| services.Add(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(XUnitLogger<>))); |
…nly if test output helper was provided, otherwise falls back to previous default logger
|
@danielgerlag the Oracle test suite is failing, can you have a look at it? thanks |
Describe the change
This PR is adding logger to capture the log entries for tests and to improve test feedback.
Describe your implementation or design
Added new
XunitLoggerclass and addedITestOutputHelperparameter to some scenario constructors.Tests
No tests are necessary.
Breaking change
No.