Voyager.UnitTestLogger
1.1.0
dotnet add package Voyager.UnitTestLogger --version 1.1.0
NuGet\Install-Package Voyager.UnitTestLogger -Version 1.1.0
<PackageReference Include="Voyager.UnitTestLogger" Version="1.1.0" />
paket add Voyager.UnitTestLogger --version 1.1.0
#r "nuget: Voyager.UnitTestLogger, 1.1.0"
// Install Voyager.UnitTestLogger as a Cake Addin #addin nuget:?package=Voyager.UnitTestLogger&version=1.1.0 // Install Voyager.UnitTestLogger as a Cake Tool #tool nuget:?package=Voyager.UnitTestLogger&version=1.1.0
Voyager.UnitTestLogger
Simple implementation of ILogger interface. Is fast to use in the unit tests because there is no need to configure DI and builders. It is possible to use it as an output to console or write the result for testing-spy purposes.
How to use the logger
The class logging into the console has the name: Voyager.UnitTestLogger.ConsoleLogger. This is an example of use in a unit test:
internal class SimpleExample
{
private MyDataReader dataReader;
[SetUp]
public void Setup()
{
dataReader = new MyDataReader(new Voyager.UnitTestLogger.ConsoleLogger<MyDataReader>());
}
[Test]
public void Example()
{
dataReader.Read();
Assert.Pass();
}
}
How to use the test-spy functionality
The class Voyager.UnitTestLogger.SpyLog either writes logs to the console and also saves the history of log operation so it could be used for asserting purposes. By a text search condition, it is possible to find out about methods that are processed during the calling of the test.
This is an example how to check the content of the history of logs:
public class ScopeTest
{
Microsoft.Extensions.Logging.ILogger logger;
[SetUp]
public void Setup()
{
logger = new Voyager.UnitTestLogger.SpyLog<ScopeTest>();
}
[Test]
public void Test()
{
logger.LogInformation("B1");
using (var scope = logger.BeginScope("S1"))
{
logger.LogInformation("L1");
logger.LogInformation("L2");
using (var scope2 = logger.BeginScope("S2"))
{
logger.LogInformation("m1");
logger.LogInformation("m2");
}
logger.LogInformation("L3");
}
logger.LogInformation("B2");
Voyager.UnitTestLogger.SpyLog<ScopeTest> casted = (logger as Voyager.UnitTestLogger.SpyLog<ScopeTest>)!;
Assert.That(casted.GetSpyContent(), Is.EqualTo(
"B1" + Environment.NewLine +
"S1" + Environment.NewLine +
" L1" + Environment.NewLine +
" L2" + Environment.NewLine +
" S2" + Environment.NewLine +
" m1" + Environment.NewLine +
" m2" + Environment.NewLine +
" L3" + Environment.NewLine +
"B2"
));
There is a method that counts the number of lines in the spy content:
internal class SpyTest
{
private Voyager.UnitTestLogger.SpyLog<ScopeTest> logger;
private MyDataReader dataReader;
[SetUp]
public void Setup()
{
logger = new Voyager.UnitTestLogger.SpyLog<ScopeTest>();
dataReader = GetReader(logger);
}
[Test]
public void CheckReadCount()
{
dataReader.Read();
dataReader.Read();
Assert.That(logger.GetLinesCount(), Is.EqualTo(GetExpectedValue()));
}
...
✍️ Authors
- @andrzejswistowski - Idea & work. Please let me know if you find out an error or suggestions.
🎉 Acknowledgements
- Przemysław Wróbel - for the icon.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
-
.NETFramework 4.7.2
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
-
net6.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.