BlazorNative.Testing 0.11.0

dotnet add package BlazorNative.Testing --version 0.11.0
                    
NuGet\Install-Package BlazorNative.Testing -Version 0.11.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="BlazorNative.Testing" Version="0.11.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorNative.Testing" Version="0.11.0" />
                    
Directory.Packages.props
<PackageReference Include="BlazorNative.Testing" />
                    
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 BlazorNative.Testing --version 0.11.0
                    
#r "nuget: BlazorNative.Testing, 0.11.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 BlazorNative.Testing@0.11.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=BlazorNative.Testing&version=0.11.0
                    
Install as a Cake Addin
#tool nuget:?package=BlazorNative.Testing&version=0.11.0
                    
Install as a Cake Tool

BlazorNative.Testing

Mount a BlazorNative page in a unit test and assert what it rendered.

Add it to your test project — it is a dev-time dependency and should never be referenced by the app itself.

dotnet add package BlazorNative.Testing

The shape of a test

using BlazorNative.Testing;

[Fact]
public async Task TheCounterIncrements()
{
    using var host = BnTestHost.Mount<CounterPage>();

    Assert.Equal("count 0", host.Tree.FindText("count 0").Text);

    await host.ClickAsync(host.Tree.FindAll("button")[0]);

    Assert.Equal("count 1", host.Tree.FindAll("text")[0].Text);
}

host.Tree is the rendered widget tree: Root, Children, Text, Styles, Props, Events, plus FindAll(nodeType) and FindText(text). Drive interaction with ClickAsync, ChangeAsync, or DispatchAsync for anything else.

What it gives you that hand-rolling does not

Children come back in real sibling order. Blazor's render queue does not create children in the order they appear — a chained child component renders after its later siblings — so the framework carries each node's own placement and the shells replay it. This package replays the same algorithm. A test that walked the render output naively would pass while your app rendered in a different order than the test asserts.

Text reads off the node you wrote. <BnText Text="Hello" /> renders a node with a text child, and the shells fold that child into its parent rather than giving it a widget. The tree does the same, so node.Text is "Hello" and not null.

It does not expose the framework's internals. The renderer and its patch model are explicitly not public API and are free to change; this package absorbs them so your tests do not depend on them.

What it does not do

  • No layout. It runs the real renderer and the real components, not Yoga — so it answers "what did my page render?", never "how big is it?".
  • No device. Register a DevHostBridge (from BlazorNative.Core) through Mount's configureServices when your page injects IMobileBridge.
  • No assertions of its own. The tree is data; your own xUnit/NUnit/TUnit assertions do the work.

Stability

Provisional. Usable and supported, but not yet frozen — the shape may move in a minor version while real consumer suites shake it out. See the API stability page.


Part of BlazorNative — write your mobile app in Blazor, ship real native widgets.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
0.11.0 39 8/21/2026
0.10.0 42 8/18/2026