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
                    
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="BStaSoft.MauiNUnitRunner.Controls" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BStaSoft.MauiNUnitRunner.Controls" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BStaSoft.MauiNUnitRunner.Controls" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BStaSoft.MauiNUnitRunner.Controls --version 1.0.0
                    
#r "nuget: BStaSoft.MauiNUnitRunner.Controls, 1.0.0"
                    
#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.
#:package BStaSoft.MauiNUnitRunner.Controls@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BStaSoft.MauiNUnitRunner.Controls&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BStaSoft.MauiNUnitRunner.Controls&version=1.0.0
                    
Install as a Cake Tool

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

  1. Include a reference to the BStaSoft.MauiNUnitRunner.Controls Nuget package in a .NET MAUI app project for your target platform(s).

  2. Include references to the project(s) with your NUnit tests or the test code itself in the .NET MAUI app project.

  3. 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();
        }
    }
    
  4. In the .NET MAUI app project's App.xaml.cs constructor, create and load an instance of the MauiNUnitRunner.Controls.TestDynamicPage ContentPage and set as the App.MainPage.

  5. The TestDynamicPage takes in an INUnitTestRunner 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);
        }
    }
    
  6. 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.

  7. To add more or change tests that are loaded or change test settings, create and set a new TestDynamicPage as the App.MainPage or directly access the underlying INUnitTestRunner from the TestDynamicPage.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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