dotnet-test
.NET test execution patterns and diagnostics. Use when running tests, analyzing test failures, or configuring test options.
What this skill does
# .NET Test Execution
## Basic Test Commands
```bash
# Run all tests in solution
dotnet test
# Run tests in specific project
dotnet test tests/MyApp.Tests/MyApp.Tests.csproj
# Run without build (faster if already built)
dotnet test --no-build
# Run without restore
dotnet test --no-restore
```
## Test Filtering
### By Name
```bash
# Filter by fully qualified name (contains)
dotnet test --filter "FullyQualifiedName~OrderService"
# Filter by test name (exact match)
dotnet test --filter "Name=CreateOrder_ValidInput_ReturnsOrder"
# Filter by display name
dotnet test --filter "DisplayName~Create Order"
```
### By Category/Trait
```bash
# Filter by trait (xUnit)
dotnet test --filter "Category=Unit"
dotnet test --filter "Category!=Integration"
# Multiple trait filters
dotnet test --filter "Category=Unit&Priority=High"
dotnet test --filter "Category=Unit|Category=Integration"
```
### By Class/Namespace
```bash
# Filter by class name
dotnet test --filter "ClassName=OrderServiceTests"
# Filter by namespace
dotnet test --filter "FullyQualifiedName~MyApp.Tests.Services"
```
### Complex Filters
```bash
# Combine with operators
# & (and), | (or), ! (not), ~ (contains), = (equals)
# Unit tests except slow ones
dotnet test --filter "Category=Unit&Category!=Slow"
# All tests in namespace containing "Order"
dotnet test --filter "FullyQualifiedName~Order&Category!=Integration"
```
## Test Output
### Verbosity Levels
```bash
# Quiet (minimal output)
dotnet test --verbosity quiet
dotnet test -v q
# Normal (default)
dotnet test --verbosity normal
# Detailed (shows all test names)
dotnet test --verbosity detailed
dotnet test -v d
# Diagnostic (maximum output)
dotnet test --verbosity diagnostic
```
### Logger Options
```bash
# Console logger with verbosity
dotnet test --logger "console;verbosity=detailed"
# TRX (Visual Studio Test Results)
dotnet test --logger trx
# JUnit format (for CI systems)
dotnet test --logger "junit;LogFileName=results.xml"
# HTML report
dotnet test --logger "html;LogFileName=results.html"
# Multiple loggers
dotnet test --logger trx --logger "console;verbosity=detailed"
```
### Results Directory
```bash
# Specify results output directory
dotnet test --results-directory ./TestResults
```
## Code Coverage
### Collect Coverage
```bash
# Basic coverage collection
dotnet test --collect:"XPlat Code Coverage"
# With Coverlet
dotnet test /p:CollectCoverage=true
# Coverlet with specific format
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
# Multiple formats
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover,cobertura\"
```
### Coverage Thresholds
```bash
# Fail if coverage below threshold
dotnet test /p:CollectCoverage=true /p:Threshold=80
# Per-type thresholds
dotnet test /p:CollectCoverage=true /p:ThresholdType=line /p:Threshold=80
```
### Coverage Reports
```bash
# Install report generator
dotnet tool install -g dotnet-reportgenerator-globaltool
# Generate HTML report
reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport
```
## Parallel Execution
```bash
# Control parallelism
dotnet test --parallel
# Limit parallel workers
dotnet test -- RunConfiguration.MaxCpuCount=4
# Disable parallel execution
dotnet test -- RunConfiguration.DisableParallelization=true
```
## Test Timeouts
```bash
# Set test timeout (milliseconds)
dotnet test -- RunConfiguration.TestSessionTimeout=60000
```
```csharp
// Per-test timeout (xUnit)
[Fact(Timeout = 5000)]
public void SlowTest() { }
// Per-test timeout (NUnit)
[Test, Timeout(5000)]
public void SlowTest() { }
```
## Configuration Files
### runsettings
```xml
<!-- test.runsettings -->
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>4</MaxCpuCount>
<ResultsDirectory>./TestResults</ResultsDirectory>
<TestSessionTimeout>600000</TestSessionTimeout>
</RunConfiguration>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat Code Coverage">
<Configuration>
<Format>cobertura</Format>
<Exclude>[*]*.Migrations.*</Exclude>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
```
```bash
# Use runsettings file
dotnet test --settings test.runsettings
```
## Test Failure Analysis
### Common Failure Patterns
| Pattern | Cause | Fix |
|---------|-------|-----|
| Assert.Equal failed | Expected != Actual | Check logic, verify test data |
| NullReferenceException | Null not handled | Add null checks, verify setup |
| TimeoutException | Test too slow | Optimize or increase timeout |
| ObjectDisposedException | Using disposed object | Fix lifetime management |
| InvalidOperationException | Invalid state | Check test setup/order |
### Debugging Failed Tests
```bash
# Run single failing test with detailed output
dotnet test --filter "FullyQualifiedName~FailingTest" -v d
# Enable blame mode to catch hangs
dotnet test --blame
# Blame with hang detection
dotnet test --blame-hang --blame-hang-timeout 60s
```
## Watch Mode
```bash
# Run tests on file changes
dotnet watch test
# Watch specific project
dotnet watch --project tests/MyApp.Tests test
# Watch with filter
dotnet watch test --filter "Category=Unit"
```
## CI/CD Integration
### Exit Codes
| Code | Meaning |
|------|---------|
| 0 | All tests passed |
| 1 | Tests failed |
| 2 | Command line error |
### CI Examples
```bash
# Azure DevOps
- task: DotNetCoreCLI@2
inputs:
command: test
arguments: '--configuration Release --logger trx'
# GitHub Actions
- run: dotnet test --configuration Release --logger "trx;LogFileName=test-results.trx"
```
See [test-filtering.md](test-filtering.md) for advanced filtering patterns.
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.