Write tests that are maintainable, self-documenting, and that promote good testing practices: 1. **Use proper assertion mechanisms**: Prefer modern assertion patterns over legacy approaches. Use built-in assertion methods that clearly indicate what is being tested.
Write tests that are maintainable, self-documenting, and that promote good testing practices:
// Bad: Custom test logic with manual exception checking
bool canceled = false;
try {
await GetAsync(useVersion, testAsync, uri, cts.Token);
} catch (TaskCanceledException) {
canceled = true;
}
Assert.True(canceled);
// Good: Use built-in assertion methods
await Assert.ThrowsAsync<TaskCanceledException>(() =>
GetAsync(useVersion, testAsync, uri, cts.Token));
Create reusable test helpers for common operations instead of duplicating test code. This improves maintainability and readability while reducing the chance of inconsistencies.
Use modern test patterns: Replace legacy patterns like “return 100 == success” with proper Assert-based validation that clearly communicates test expectations and failures.
Remove commented-out or dead test code that doesn’t contribute to validation. Keep tests clean and focused on what’s actually being tested.
Enter the URL of a public GitHub repository