- Features
- Installation
- Usage
- How It Works
- Command Reference
- Development
- Tech Stack
- License
- Contributing
A .NET tool for automatically adding data-testid attributes to Razor components for improved testability.
- Automatic test-id injection: Adds
data-testidattributes to root-level HTML elements in Razor files - Multiple processing modes: Process single files, folders, projects, or entire solutions
- Smart detection: Only processes files that need updates
- Preserve formatting: Maintains your existing code formatting and indentation
- Replace existing: Updates existing
data-testidattributes if present - Dry-run mode: Preview changes before applying them
- Beautiful CLI: User-friendly command-line interface with progress reporting
dotnet tool install -g AutoTestIdOr build from source:
git clone https://github.com/yourusername/AutoTestId.git
cd AutoTestId
dotnet buildautotestid file Component.razor
# With custom test-id
autotestid file Component.razor --test-id "MyCustomId"
# Preview changes without modifying
autotestid file Component.razor --dry-runautotestid folder ./src
# Process recursively (default)
autotestid folder ./src --recursive
# Exclude specific directories
autotestid folder ./src --exclude bin --exclude obj
# Custom file pattern
autotestid folder ./src --pattern "*.razor"autotestid project MyApp.csproj
# Preview changes
autotestid project MyApp.csproj --dry-run
# Exclude directories
autotestid project MyApp.csproj --exclude wwwrootautotestid solution MyApp.sln
# Exclude specific projects
autotestid solution MyApp.sln --exclude-project "Tests"
# Include test projects (excluded by default)
autotestid solution MyApp.sln --include-tests
# Process only specific projects
autotestid solution MyApp.sln --include-project "MyApp.Web" --include-project "MyApp.Components"AutoTestId processes Razor files and adds data-testid attributes to all root-level HTML elements:
Before:
<div class="card">
<h2>@Title</h2>
<p>@Description</p>
</div>
<footer>
<span>@Copyright</span>
</footer>After:
<div data-testid="ProductCard" class="card">
<h2>@Title</h2>
<p>@Description</p>
</div>
<footer data-testid="ProductCard">
<span>@Copyright</span>
</footer>The test-id value is derived from the component filename (without extension) by default.
-h, --help- Show help information-v, --version- Show version information
Process a single Razor file.
Arguments:
<FILE>- Path to the Razor file to process
Options:
-t, --test-id <ID>- Custom test ID value to use (defaults to filename)-d, --dry-run- Preview changes without modifying files
Process all Razor files in a folder.
Arguments:
<FOLDER>- Path to the folder containing Razor files
Options:
-r, --recursive- Process subdirectories recursively (default: true)-p, --pattern <PATTERN>- File pattern to match (default: *.razor)-d, --dry-run- Preview changes without modifying files-e, --exclude <DIR>- Directories to exclude (can be specified multiple times)
Process all Razor files in a .csproj project.
Arguments:
<PROJECT>- Path to the .csproj file
Options:
-d, --dry-run- Preview changes without modifying files-l, --include-linked- Include linked files in processing-e, --exclude <DIR>- Directories to exclude (can be specified multiple times)
Process all Razor files in a .sln solution.
Arguments:
<SOLUTION>- Path to the .sln file
Options:
-d, --dry-run- Preview changes without modifying files-i, --include-project <NAME>- Specific projects to include (can be specified multiple times)-e, --exclude-project <NAME>- Projects to exclude (can be specified multiple times)-t, --include-tests- Include test projects in processing
dotnet testdotnet builddotnet run -- file MyComponent.razor- .NET 9
- Shouldly
- xunit.v3
- xunit.runner.visualstudio
- Spectre.Console.Cli
Planned work and known limitations are tracked in the open issues. Contributions toward them are welcome.
MIT License - see LICENSE file for details.
Contributions are welcome. Open an issue first to discuss any significant change.
- Fork the repository and create your branch (
git checkout -b feat/my-feature) - Commit your changes (
git commit -m 'feat: ...') - Push the branch and open a Pull Request
Built by Atypical Consulting. We also make NuGetKeep, a self-hosted NuGet server with supply-chain quarantine.
