Overview
The Intent.UnitTesting module adds infrastructure and support for unit testing your application using xUnit. It generates test project scaffolding, test stubs for application logic, and integrates with popular mocking frameworks.This module currently generates unit test stubs only — actual test implementations must be written manually. AI-powered test generation is available through the Intent.AI.UnitTests module.
What Gets Generated
Test Projects
- xUnit test projects with proper structure and dependencies
- Test infrastructure including base classes and utilities
- NuGet package references for xUnit and mocking frameworks
Test Stubs
The module generates stub test classes for:- Command Handlers (for CQRS-based services)
- Query Handlers (for CQRS-based services)
- Service Operations (for traditional services)
- Domain Event Handlers
- Integration Event Handlers
Application.Tests/CommandHandlers/CreateCustomerCommandHandlerTests.cs
Installation
Prerequisites
- A .NET application created in Intent Architect
- Application logic (Commands, Queries, or Services) to test
Installation Steps
Install the module
In Intent Architect, right-click on your application and select Manage Modules. Search for
Intent.UnitTesting and install it.Configure generation mode
Navigate to Application Settings and configure whether test generation should be opt-in or automatic (see Generation Mode).
Choose mocking framework
Select your preferred mocking framework in Application Settings (Moq or NSubstitute).
Configuration
Generation Mode
The module defaults to opt-in mode for test generation. Tests are only generated for elements explicitly marked with theUnit Test stereotype.
Change to automatic generation:
- Open Application Settings
- Navigate to UnitTesting section
- Set Generation Mode to
Generate for all
- Commands
- Queries
- Services / Operations
Mocking Framework
Choose between supported mocking libraries:- Moq (default) - Popular, fluent API
- NSubstitute - Simpler syntax, natural C# syntax
- Navigate to Application Settings
- Find UnitTesting section
- Select Mocking Framework
Usage Examples
Opt-In Test Generation
To generate tests for specific elements:Apply Unit Test stereotype
In the Services Designer, right-click on a Command, Query, Service, or Operation and select Add Stereotype → Unit Test.

Using Moq (Default)
Tests/GetOrderQueryHandlerTests.cs
Using NSubstitute
Tests/DeleteProductCommandHandlerTests.cs
Best Practices
Use Descriptive Test Names
Follow the pattern
MethodName_Scenario_ExpectedBehavior for clear test intent.Arrange-Act-Assert
Structure tests with clear sections: setup (Arrange), execution (Act), and verification (Assert).
Test Edge Cases
Don’t just test the happy path — include null checks, boundary conditions, and error scenarios.
Keep Tests Isolated
Each test should be independent and not rely on the execution order or state from other tests.
Testing Command Handlers
Testing Query Handlers
Integration with Other Modules
AI Unit Tests
Use AI to automatically implement test logic instead of writing manually.
Integration Testing
Combine with Intent.AspNetCore.IntegrationTesting for full-stack API tests.
FluentValidation
Tests automatically include validators when using Intent.Application.FluentValidation.
Azure Pipelines
Generated tests run automatically in CI/CD pipelines.
Related Resources
Next Steps
AI Unit Tests
Generate complete test implementations with AI
Integration Testing
Test your APIs end-to-end with integration tests
CI/CD Setup
Automate test execution in Azure Pipelines
