Prompt
Write tests that are maintainable, self-documenting, and that promote good testing practices:
- Use proper assertion mechanisms: Prefer modern assertion patterns over legacy approaches. Use built-in assertion methods that clearly indicate what is being tested.
// 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.
- Use appropriate conditional attributes to ensure tests properly convert Debug.Assert failures to test failures and run only when the tested functionality is supported.