wan24-Tests
1.5.0
See the version list below for details.
dotnet add package wan24-Tests --version 1.5.0
NuGet\Install-Package wan24-Tests -Version 1.5.0
<PackageReference Include="wan24-Tests" Version="1.5.0" />
paket add wan24-Tests --version 1.5.0
#r "nuget: wan24-Tests, 1.5.0"
// Install wan24-Tests as a Cake Addin #addin nuget:?package=wan24-Tests&version=1.5.0 // Install wan24-Tests as a Cake Tool #tool nuget:?package=wan24-Tests&version=1.5.0
wan24-Tests
This library contains some test project helpers.
Usage
How to get it
This package is available as
NuGet package wan24-Tests
.
Add options using an assembly attribute
Create the file Attributes.cs
with this content:
using wan24.Tests;
[assembly: TestsOptions(...)]
You can set several options using the attribute properties. You may also
implement a custom attribute which extends TestsOptions
and may override any
event handling method:
Method | Description |
---|---|
OnBeforeInitialization |
Run before global initialization |
OnAfterInitialization |
Run after global initialization |
OnBeforeTestsInitialization |
Run before tests initialization |
OnBeforeTestsInitialization |
Run before tests initialization |
Tests initialization
The tests initialization does the following for you:
- Configure
wan24-Core
NuGet package logging (using a log file and the console) - Configure the MS test project logging
- Logging background errors
- Logging object validation errors of the
ObjectValidation
NuGet package - Optional enable creating a construction stack information for disposable
types which extend
wan24.Core.Disposable(Record)Base
- Booting
wan24-Core
It needs to run before any tests are being executed. To achive this, please
add the file Initialization.cs
to your test project:
namespace wan24.Tests
{
[TestClass]
public class Initialization
{
[AssemblyInitialize]
public static void Init(TestContext tc) => TestsInitialization.Init(tc);
}
}
The TestsInitialization
type exports some static properties:
Property | Description |
---|---|
LoggerFactory |
A logger factory |
Options |
The used tests options (TestsOptionsAttribute ) |
Using TestBase
as base class for a test
Example test:
[TestClass]
public class YourTests : TestBase
{
...
}
The TestBase
will log the currently running test, which makes it more easy
to see where tests failed, if you're running them from the CLI. For running
initialization code after the TestOptionsAttribute
event handlers you may
override the InitTests
method:
[TestInitialize]
public override void InitTests()
{
base.InitTests();
// Your tests initialization code here
}
The TestBase
type defines these properties:
Property | Description |
---|---|
TestContext |
The current test context |
Logger |
An ILogger instance, using Logging.Logger or a new created one from TestsInitialization.LoggerFactory |
Interface testing
There are some static test methods for types which implement interfaces:
Interface | Test method |
---|---|
IDictionary(<tKey, tValue>) |
DictionaryTests.RunTests |
ICollection(<T>) |
CollectionTests.RunTests |
IList(<T>) |
ListTests.RunTests |
I(Async)Enumerable(<T>) |
EnumerableTests.RunTests(Async) |
Since it's impossible to define a fixed test data set which works well for all
types which implement those interfaces (-> but we never know how a type
implemented an interface for which data type), those tests do only cover a
very basic set of functional tests, and you'll have to provide a test data set
for each method (see Tests.cs
in the source code). Example:
DictionaryTests.RunTests<OrderedDictionary<string, string>, string, string>(
new KeyValuePair<string, string>("a", "a"),
new KeyValuePair<string, string>("b", "b")
);
In case the tested type can't be constructed from the static test methods, there are overloads which accept an existing instance. A test data set must contain at last two items, while an existing instance may contain test data or not - that depends on the interface (please see the DocComments for each test methods requirements).
More detailed tests need to be implemented by yourself. However, I'm open for adding more basic tests, if they could be applied to all types which implement an interface. Don't hesitate to contribute.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.Logging.Console (>= 8.0.1)
- MSTest.TestFramework (>= 3.6.2)
- ObjectValidation (>= 2.8.0)
- System.Text.Json (>= 8.0.5)
- wan24-Core (>= 2.44.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.