https://github.com/godeltech/godeltech.xunit.logging
https://github.com/godeltech/godeltech.xunit.logging
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/godeltech/godeltech.xunit.logging
- Owner: GodelTech
- License: mit
- Created: 2021-11-25T14:45:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-15T20:39:38.000Z (5 months ago)
- Last Synced: 2024-12-19T14:34:54.712Z (5 months ago)
- Language: C#
- Size: 72.3 KB
- Stars: 0
- Watchers: 10
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GodelTech.XUnit.Logging
GodelTech.XUnit.Logging is a helper library for capturing logs in xUnit tests. It enables seamless integration of logging within xUnit test frameworks, allowing developers to access log entries and utilize them in their tests.
## Overview`GodelTech.XUnit.Logging` contains helper for getting logs in xunit testing.
```c#
public class AppTestFixture : WebApplicationFactory
{
public ITestOutputHelper Output { get; set; }public ITestLoggerContextAccessor TestLoggerContextAccessor { get; } = new TestLoggerContextAccessor();
protected override IHostBuilder CreateHostBuilder()
{
var builder = Host
.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
x =>
{
x.UseStartup()
.UseTestServer()
.ConfigureTestLogging(Output, TestLoggerContextAccessor);
}
);return builder;
}protected override IHost CreateHost(IHostBuilder builder)
{
builder.UseContentRoot(Directory.GetCurrentDirectory());return base.CreateHost(builder);
}
}
```## Exmaple of usage
```c#
public sealed class SomeTests : IDisposable
{
private readonly AppTestFixture _fixture;public SomeTests(ITestOutputHelper output)
{
_fixture = new AppTestFixture
{
Output = output
};
}public void Dispose()
{
_fixture.Dispose();
}// test methods
}
```To access logs entries use:
```c#
_fixture
.TestLoggerContextAccessor
.TestLoggerContext
.Entries;
```
You can check example of usage in Integration Tests for this library here: https://github.com/GodelTech/GodelTech.XUnit.Logging/tree/main/test/GodelTech.XUnit.Logging.IntegrationTests.# License
This project is licensed under the MIT License. See the LICENSE file for more details.