Voyager.UnitTestLogger
1.0.2
See the version list below for details.
dotnet add package Voyager.UnitTestLogger --version 1.0.2
NuGet\Install-Package Voyager.UnitTestLogger -Version 1.0.2
<PackageReference Include="Voyager.UnitTestLogger" Version="1.0.2" />
paket add Voyager.UnitTestLogger --version 1.0.2
#r "nuget: Voyager.UnitTestLogger, 1.0.2"
// Install Voyager.UnitTestLogger as a Cake Addin #addin nuget:?package=Voyager.UnitTestLogger&version=1.0.2 // Install Voyager.UnitTestLogger as a Cake Tool #tool nuget:?package=Voyager.UnitTestLogger&version=1.0.2
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. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Logging.Abstractions (>= 6.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.