StoicDreams.TestFramework 1.1.14

There is a newer version of this package available.
See the version list below for details.
dotnet add package StoicDreams.TestFramework --version 1.1.14                
NuGet\Install-Package StoicDreams.TestFramework -Version 1.1.14                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StoicDreams.TestFramework" Version="1.1.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StoicDreams.TestFramework --version 1.1.14                
#r "nuget: StoicDreams.TestFramework, 1.1.14"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StoicDreams.TestFramework as a Cake Addin
#addin nuget:?package=StoicDreams.TestFramework&version=1.1.14

// Install StoicDreams.TestFramework as a Cake Tool
#tool nuget:?package=StoicDreams.TestFramework&version=1.1.14                

Stoic Dreams Test Framework

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 Moq mocking framework.

Project Goals

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.

Framework Features

  • Inclusion of Moq mocking framework to use for mocking components.
  • Inclusion of FluentAssertions framework to use for human readable assertions.
  • Automatic default mocking (using Moq's Mock framework) of a class's constructor dependencies when running unit tests.
  • Test framework agnostic: While we use XUnit, we have no restrictions against using other frameworks such as NUnit, MSTest, etc.

Noted Restrictions

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:

  • Classes being tested with TestFramework.ArrangeUnitTest should have a single public constructor. If a class has multiple public constructors it will use the first one.

Setting up your Test Project

Add the StoicDreams.TestFramework Nuget package to your test project.

<ItemGroup>
	<PackageReference Include="StoicDreams.TestFramework" Version="1.1.14" />
</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)
	{
		IActions<SampleParent> actions = ArrangeUnitTest<SampleParent>(options =>
		{
			options.GetMock<ISampleChildA>().Setup(m => m.DoSomething(input)).Returns($"Mock A: {input}");
			options.GetMock<ISampleChildB>().Setup(m => m.DoSomething(input)).Returns($"Mock B: {input}");
		});

		actions.Act(arrangment => arrangment.Service.DoSomething(input));

		actions.Assert(arrangement =>
		{
			string? result = arrangement.GetResult<string>();
			result.Should().NotBeNullOrWhiteSpace();
			result.Should().BeEquivalentTo($"Parent: Mock A: {input} - Mock B: {input}");
		});
	}
}

Author

Erik Gassler - Stoic Dreams - Just a simpleton who likes making stuff with bits and bytes.

Support - Visit my Patreon 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 Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.6.9 41 11/28/2024
1.6.8 41 11/27/2024
1.6.7 1,200 5/25/2024
1.6.6 109 5/25/2024
1.6.5 119 5/24/2024
1.6.4 136 5/24/2024
1.6.3 1,155 1/4/2024
1.6.2 521 12/7/2023
1.6.1 268 11/16/2023
1.6.0 207 11/15/2023
1.5.16 207 11/15/2023
1.5.15 1,085 10/17/2023
1.5.14 1,392 8/29/2023
1.5.13 698 8/17/2023
1.5.12 517 8/11/2023
1.5.11 301 8/11/2023
1.5.10 303 8/11/2023
1.5.9 301 8/11/2023
1.5.8 310 8/11/2023
1.5.7 300 8/11/2023
1.5.6 290 8/11/2023
1.5.5 304 8/11/2023
1.5.4 319 8/11/2023
1.5.3 295 8/11/2023
1.5.2 172 8/10/2023
1.5.1 149 8/10/2023
1.4.53 320 7/30/2023
1.4.51 4,500 4/4/2023
1.4.50 339 4/4/2023
1.4.49 1,548 3/1/2023
1.4.48 1,176 2/3/2023
1.4.40 530 1/24/2023
1.4.37 414 1/24/2023
1.4.36 729 1/5/2023
1.4.32 446 1/5/2023
1.4.31 445 1/5/2023
1.4.30 440 1/5/2023
1.4.21 503 1/3/2023
1.4.20 508 12/12/2022
1.4.9 934 9/20/2022
1.4.7 791 8/28/2022
1.4.2 1,193 8/11/2022
1.4.1 4,923 7/17/2022
1.3.1 696 7/17/2022
1.2.12 676 7/17/2022
1.2.11 728 7/11/2022
1.2.10 684 7/9/2022
1.2.8 715 7/9/2022
1.2.7 694 7/9/2022
1.2.6 701 7/9/2022
1.2.4 681 7/9/2022
1.2.3 666 7/8/2022
1.1.14 686 7/8/2022
1.1.13 691 7/8/2022
1.1.12 403 7/8/2022
1.1.11 407 7/8/2022
1.1.10 404 7/8/2022
1.1.9 690 7/8/2022
1.1.5 412 7/8/2022
1.0.4 431 7/7/2022
1.0.3 428 7/4/2022
1.0.2 393 7/3/2022
0.1.13 419 7/3/2022
0.1.12 403 7/3/2022
0.1.11 415 7/3/2022
0.1.10 411 7/3/2022
0.1.9 424 7/3/2022

Development Release