Testing Strategy
A comprehensive testing approach includes:- Unit Tests: Test individual template methods and helpers
- Integration Tests: Test entire template outputs
- Scenario Tests: Test with various metadata configurations
- Regression Tests: Ensure changes don’t break existing functionality
- Manual Testing: Verify visual output and edge cases
Test Project Setup
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Verify.Xunit" Version="22.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyModule\MyModule.csproj" />
</ItemGroup>
</Project>
Unit Testing Templates
Testing Template Methods
Test individual methods in templates:EntityTemplateTests.cs
Testing Helper Classes
EntityHelperTests.cs
Snapshot Testing
Use Verify to test entire template outputs:Basic Snapshot Test
EntityTemplateSnapshotTests.cs
Snapshot File Example
The first run creates a snapshot file:Snapshots/EntityTemplateSnapshotTests.EntityTemplate_GeneratesCorrectOutput.verified.txt
Testing Decorators
Unit Testing Decorators
LoggingDecoratorTests.cs
Testing Factory Extensions
ValidationExtensionTests.cs
Integration Testing
Full Module Integration Tests
ModuleIntegrationTests.cs
Testing with Real Metadata
Create Test Applications
Set up test Intent applications:Test Against Fixtures
FixtureBasedTests.cs
Testing CSharp Builder Usage
CSharpBuilderTests.cs
Manual Testing
Test Application Setup
# Add local repository
intent repository add local file:///path/to/your/modules
# Install module
intent install-module MyModule
# Run Software Factory
intent run-software-factory
Continuous Testing
GitHub Actions
.github/workflows/test.yml
Test Organization
Recommended Structure
Best Practices
Write Tests First
Test Edge Cases
Use Descriptive Names
Keep Tests Independent
Troubleshooting Tests
Snapshots not matching
Snapshots not matching
- Run
dotnet testlocally to update snapshots - Ensure line endings are consistent (Git settings)
- Check for environment-specific paths
- Use
UseDirectory()andUseFileName()for organization
Mocks not working
Mocks not working
- Verify all dependencies are mocked
- Check Setup() calls match actual usage
- Use
It.IsAny<T>()for flexible matching - Enable Moq strict mode to catch issues
Tests failing in CI
Tests failing in CI
- Check path separators (use
Path.Combine) - Ensure test files are included in build
- Verify .NET SDK version matches
- Check for timezone or culture dependencies
Next Steps
Creating Modules
Complete guide to module creation
Creating Templates
Template development guide
Creating Decorators
Decorator development guide
Factory Extensions
Factory extension development