bUnit is a testing library for Blazor components. You can easily define components under test in C# or Razor syntax and verify outcome using semantic HTML diffing/comparison logic. You can interact with and inspect the component under test, trigger event handlers, provide cascading values, and inject services. bUnit also includes a complete fake implementation of Blazor's authentication and authorization logic, navigation manager, and JSInterop.
$ dotnet add package bunitbUnit is a testing library for Blazor Components. Its goal is to make it easy to write comprehensive, stable unit tests. With bUnit, you can:
IJSRuntime, Blazor authentication and authorization, and othersbUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, MSTest and TUnit, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run.
Go to bUnit.dev to learn more.
bUnit is available on NuGet in various incarnations. Most should just pick the bUnit package:
<table border="0"> <tr> <td align="center" width="250"> <a href="https://www.lambdatest.com/?utm_source=bunit&utm_medium=sponsor" target="_blank"> <img src="https://www.lambdatest.com/blue-logo.png" style="vertical-align: middle;" width="250" height="45" /> <br /> LambdaTest </a> </td> </tr> </table> <a href="https://github.com/bUnit-dev/bUnit/graphs/contributors"> <img src="https://contrib.rocks/image?repo=bUnit-dev/bUnit" /> </a>| Name | Description | NuGet Download Link |
|---|---|---|
| bUnit | Adds support for testing Blazor components. | |
| bUnit.template | Template, which currently creates xUnit-based bUnit test projects only. | |
| bUnit.generators | Source code generators to minimize code setup in various situations. | |
| bUnit.web.query | bUnit implementation of testing-library.com's query APIs. |
To get started, head to the getting started documentation to learn more.
| bUnit version | .NET version |
|---|---|
| 1.x | ≥ .netcore3.1 && ≤ .net 9 |
| 2.x | ≥ .net8 |
For a migration guide, see Upgrading bUnit.
A huge thank you to the sponsors of bUnit. The higher tier sponsors are:
Shout outs and a big thank you to all the contributors to the library, including those that raise issues, provide input to issues, and those who send pull requests. Thank you!
These good people have contributed code or documentation to bUnit:
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.
This project is supported by the .NET Foundation.