vialTesting

UmbNav includes comprehensive testing infrastructure to ensure reliability and help you test your own extensions.

Test Types

UmbNav uses two types of tests:

Type
Framework
Location
Purpose

Unit Tests

xUnit + Moq

Umbraco.Community.UmbNav.Core.Tests/

Backend C# logic

E2E Tests

Playwright

Umbraco.Community.UmbNav/tests/

Backoffice UI

Test Coverage

Unit Tests (C#)

The C# unit tests cover:

  • UmbNavMenuBuilderService - Menu processing logic

    • Item filtering

    • Content resolution

    • Build options application

    • Child processing

    • Active state detection

    • Authentication-based visibility

  • UmbNavBuildOptions - Options behavior

    • Default values

    • Property removal

    • Depth limiting

  • UmbNavItemExtensions - Extension methods

    • URL generation

    • Active state checking

    • HTML generation

E2E Tests (Playwright)

The Playwright tests cover:

  • Adding Items

    • Add content items

    • Add link items

    • Add text items

    • Inline item creation

  • Editing Items

    • Rename items

    • Modify settings

  • Validation

    • Empty text item validation

    • Required field validation

  • UI Features

    • Toggle all button visibility

    • Text items configuration

Running Tests

Unit Tests

E2E Tests

Prerequisites

For Unit Tests

  • .NET 10 SDK

  • Test dependencies (automatically restored):

    • xUnit

    • Moq

    • Microsoft.NET.Test.Sdk

For E2E Tests

  • Node.js 18+

  • Playwright browsers (installed via npx playwright install)

  • Running Umbraco instance with test content

  • Environment variables:

    • Test user credentials (in .env file)

Test Configuration

Unit Test Project

The test project references:

Playwright Configuration

playwright.config.ts:

Writing Tests

Unit Test Pattern

E2E Test Pattern

CI/CD Integration

Tests can run in GitHub Actions:

Best Practices

  1. Test behavior, not implementation - Focus on what the code does, not how

  2. Use descriptive names - MethodName_Scenario_ExpectedResult

  3. Keep tests independent - Each test should be runnable in isolation

  4. Mock external dependencies - Use Moq for services, caches, etc.

  5. Test edge cases - Null inputs, empty collections, boundary values

  6. Use test data builders - Create reusable test data creation methods

Last updated

Was this helpful?