BStaSoft.MauiNUnitRunner.Controls
1.0.0
dotnet add package BStaSoft.MauiNUnitRunner.Controls --version 1.0.0
NuGet\Install-Package BStaSoft.MauiNUnitRunner.Controls -Version 1.0.0
<PackageReference Include="BStaSoft.MauiNUnitRunner.Controls" Version="1.0.0" />
<PackageVersion Include="BStaSoft.MauiNUnitRunner.Controls" Version="1.0.0" />
<PackageReference Include="BStaSoft.MauiNUnitRunner.Controls" />
paket add BStaSoft.MauiNUnitRunner.Controls --version 1.0.0
#r "nuget: BStaSoft.MauiNUnitRunner.Controls, 1.0.0"
#:package BStaSoft.MauiNUnitRunner.Controls@1.0.0
#addin nuget:?package=BStaSoft.MauiNUnitRunner.Controls&version=1.0.0
#tool nuget:?package=BStaSoft.MauiNUnitRunner.Controls&version=1.0.0
MauiNUnitRunner
NUnit test runner for .NET MAUI based projects.
This project looks to revive the NUnit and Xamarin NUnitLite unit test runner projects and combine the granular interface provided by the Xamarin runner with the full functionality provided by the NUnit framework and built for .NET MAUI.
Features include:
- Exploring loaded tests by namespace, class, and method.
- Running tests and test cases individually or by namespace, class, or method.
- Viewing overall results and individual results with details.
- Saving test results to a file.
- Ability to write the output of test results to the console as tests are ran.
- Running tests on a background thread, leaving the UI thread available to perform other work.
- This can also help avoid deadlock situations when a test requires the UI thread.
- Supports all major platforms supported by .NET MAUI.
- Extensible design allows for customization of existing or creation of new behaviors and views.
Note: The controls are optimized for landscape orientation on larger devices (e.g. tablets). While the application will function in portrait orientation and on smaller devices, some text may be clipped.
Usage
Include a reference to the
BStaSoft.MauiNUnitRunner.Controls
Nuget package in a .NET MAUI app project for your target platform(s).Include references to the project(s) with your NUnit tests or the test code itself in the .NET MAUI app project.
On the .NET MAUI app project's
MauiAppBuilder
method, call the.UseMauiNUnitRunner()
method to initialize the MauiNUnitRunner controls.using MauiNUnitRunner.Controls; public static class MauiProgram { public static MauiApp CreateMauiApp() { MauiAppBuilder builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() // Initialize using the MauiNUnitRunner .UseMauiNUnitRunner(); return builder.Build(); } }
In the .NET MAUI app project's
App.xaml.cs
constructor, create and load an instance of theMauiNUnitRunner.Controls.TestDynamicPage
ContentPage and set as theApp.MainPage
.The
TestDynamicPage
takes in anINUnitTestRunner
to which test assemblies and test settings are added. This should include the current app's assembly if it contains tests to run.using MauiNUnitRunner.Controls; public partial class App : Application { public App() { InitializeComponent(); // It is recommended to set the app theme UserAppTheme = Current?.RequestedTheme ?? AppTheme.Unspecified; // Specify any test settings Dictionary<string, object> settings = new Dictionary<string, object>(); settings.Add("MySetting", "value"); // Add assemblies with unit tests to test runner NUnitTestRunner runner = new NUnitTestRunner(); runner.AddTestAssembly(GetType().Assembly, settings); // Create initial test page TestDynamicPage page = new TestDynamicPage(runner); // Set test page as main page MainPage = new NavigationPage(page); } }
It is recommended to build the .NET MAUI app project in Debug. NUnit will not be able to work correctly on some platforms in Release builds.
To add more or change tests that are loaded or change test settings, create and set a new
TestDynamicPage
as theApp.MainPage
or directly access the underlyingINUnitTestRunner
from theTestDynamicPage.TestRunner
property.
Test Listener
Add an NUnit.Framework.Interfaces.ITestListener
such as the MauiNUnitRunner.Controls.NUnitTestListener
using the INUnitTestRunner.AddTestListener
method to output tests messages and results as tests are ran. Multiple and custom test listeners can be added.
// Add an optional test listener to get test output and progress
NUnitTestListener listener = new NUnitTestListener();
listener.WriteOutput += Console.WriteLine;
runner.AddTestListener(listener);
Extensibility
The MauiNUnitRunner.Controls
namespace exposes the individual ContentViews used to populate the TestDynamicPage
as well as marking a number of key methods virtual. This allows for the construction of custom views and pages or modification of the existing page's behavior.
License
See the License file for licensing details.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- CommunityToolkit.Maui (>= 8.0.0)
- Microsoft.Maui.Controls (>= 8.0.14)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.14)
- NUnit (>= 3.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 488 | 5/31/2024 |
1.0.0-pre1 | 114 | 5/22/2024 |