![]() |
VOOZH | about |
dotnet add package StoicDreams.TestFramework --version 1.9.1
NuGet\Install-Package StoicDreams.TestFramework -Version 1.9.1
<PackageReference Include="StoicDreams.TestFramework" Version="1.9.1" />
<PackageVersion Include="StoicDreams.TestFramework" Version="1.9.1" />Directory.Packages.props
<PackageReference Include="StoicDreams.TestFramework" />Project file
paket add StoicDreams.TestFramework --version 1.9.1
#r "nuget: StoicDreams.TestFramework, 1.9.1"
#:package StoicDreams.TestFramework@1.9.1
#addin nuget:?package=StoicDreams.TestFramework&version=1.9.1Install as a Cake Addin
#tool nuget:?package=StoicDreams.TestFramework&version=1.9.1Install as a Cake Tool
Nuget: www.nuget.org/packages/StoicDreams.TestFramework
GitHub: github.com/StoicDreams/TestFramework
This library includes an abstract class called TestFramework that developers can inherit from their test classes to access helper methods for unit and integration tests.
Functionality includes extending and simplifying functionality from the NSubstitute mocking framework (We moved away from Moq over security concerns that came up with their 4.20 release.)
The goal of this library is to provide a framework to use in unit tests and integration tests that grealy simplify organizing tests using the Arrange / Act / Assert testing pattern.
This framework assumes use of IServiceCollection and IServiceProvider to handle dependency injection. And so, also uses ServiceCollection to manage components and build IServiceProvider which is used to handle dependency injection.
Because of this usage:
TestFramework.ArrangeUnitTest should have a single public constructor. If a class has multiple public constructors it will use the first one.Add the StoicDreams.TestFramework Nuget package to your test project.
<ItemGroup>
<PackageReference Include="StoicDreams.TestFramework" Version="1.9.1" />
</ItemGroup>
Add assembly settings that will allow testing to access internal classes for the projects you are testing.
This update needs to be added to any project that utilizes internal classes.
Usings.cs
// Your existing global using statements
global using System;
...
// Add these 2 lines to allow testing to access internal classes
using System.Runtime.CompilerServices;
// Needed by the testing framework to access internals during reflection for automated mocking
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
// Reference your test project so it can see your main projects internals
[assembly: InternalsVisibleTo("MyCompany.MyApp.Tests")]
Inherit the StoicDreams.TestFramework class in all test files.
ExampleTests.cs (See a full example on GitHub)
namespace MyCompany.MyApp;
public class SampleChildATests : StoicDreams.TestFramework
{
[Theory]
[InlineData("Test One")]
[InlineData("Test Two")]
public void Verify_DoSomething_ReturnsExpectedData(string input)
{
ArrangeUnitTest<SampleParent>(options =>
{
options.GetService<ISampleChildA>().DoSomething(input).Returns($"Mock A: {input}");
options.GetService<ISampleChildB>().DoSomething(input).Returns($"Mock B: {input}");
})
.Act(arrangment => arrangment.Service.DoSomething(input))
.Assert(arrangement =>
{
string? result = arrangement.GetResult<string>();
result.Should().NotBeNullOrWhiteSpace();
result.Should().BeEquivalentTo($"Parent: Mock A: {input} - Mock B: {input}");
});
}
}
Erik Gassler - Stoic Dreams - Forging solutions for tomorrow's software development.
Support - Visit Stoic Dreams' GitHub Sponsor page if you would like to provide support.
Software Development Standards - Check out my Simple-Holistic-Agile Software Engineering Standards website to see my standards for developing software.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on StoicDreams.TestFramework:
| Package | Downloads |
|---|---|
|
StoicDreams.TestFramework.Blazor
Extended functionality of Stoic Dreams Test Framework, adding funtionality to handle testing against rendered .razor components for unit and integration testing. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.1 | 239 | 5/28/2026 |
| 1.9.0 | 1,683 | 2/20/2026 |
| 1.8.5 | 886 | 1/14/2026 |
| 1.8.4 | 143 | 1/14/2026 |
| 1.8.3 | 150 | 1/14/2026 |
| 1.8.2 | 144 | 1/14/2026 |
| 1.8.1 | 143 | 1/13/2026 |
| 1.8.0 | 148 | 1/13/2026 |
| 1.7.2 | 1,298 | 8/15/2025 |
| 1.7.1 | 1,343 | 3/18/2025 |
| 1.7.0 | 1,102 | 12/4/2024 |
| 1.6.9 | 274 | 11/28/2024 |
| 1.6.8 | 262 | 11/27/2024 |
| 1.6.7 | 1,566 | 5/25/2024 |
| 1.6.6 | 256 | 5/25/2024 |
| 1.6.5 | 280 | 5/24/2024 |
| 1.6.4 | 283 | 5/24/2024 |
| 1.6.3 | 1,314 | 1/4/2024 |
| 1.6.2 | 674 | 12/7/2023 |
| 1.6.1 | 394 | 11/16/2023 |
Development Release