Agent Skills: bUnit - Blazor Component Testing

Blazor component testing with bUnit. Use when writing unit tests for Blazor components, testing user interactions, mocking services/dependencies, testing MudBlazor components, testing components with Neatoo domain objects, or debugging component rendering issues.

UncategorizedID: keithdv/ClaudeSkills/bunit

Skill Files

Browse the full folder contents for bunit.

Download Skill

Loading file tree…

skills/bunit/SKILL.md

Skill Metadata

Name
bunit
Description
Blazor component testing with bUnit. Use when writing unit tests for Blazor components, testing user interactions, mocking services/dependencies, testing MudBlazor components, testing components with Neatoo domain objects, or debugging component rendering issues.

bUnit - Blazor Component Testing

Overview

bUnit is a testing library for Blazor components that enables testing without a browser. It provides:

  • Component rendering in a test environment
  • DOM assertions and markup verification
  • User interaction simulation (clicks, inputs, form submissions)
  • Service mocking and dependency injection
  • Async testing with waiting utilities
  • Blazor lifecycle testing

Installation

# Add bUnit with xUnit support
dotnet add package bunit

# Or individual packages
dotnet add package bunit.core
dotnet add package bunit.web
dotnet add package bunit.xunit   # For xUnit integration

Quick Start

Basic Component Test

public class CounterTests : TestContext
{
    [Fact]
    public void Counter_InitialCount_IsZero()
    {
        // Arrange & Act
        var cut = RenderComponent<Counter>();

        // Assert
        cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
    }

    [Fact]
    public void Counter_ClickButton_IncrementsCount()
    {
        // Arrange
        var cut = RenderComponent<Counter>();

        // Act
        cut.Find("button").Click();

        // Assert
        cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
    }
}

Additional Resources

For detailed guidance, see:

Official Documentation