Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions docs/core/testing/mstest-analyzers/design-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,55 @@ Design rules help you create and maintain test suites that adhere to proper desi

| Rule ID | Title | Severity | Fix Available |
|---------|-------|----------|---------------|
| [MSTEST0004](mstest0004.md) | Public types should be test classes | Info | Yes |
| [MSTEST0006](mstest0006.md) | Avoid ExpectedException attribute | Info | Yes |
| [MSTEST0015](mstest0015.md) | Test method should not be ignored | None (opt-in) | No |
| [MSTEST0016](mstest0016.md) | Test class should have test method | Info | No |
| [MSTEST0019](mstest0019.md) | Prefer TestInitialize over constructors | None (opt-in) | Yes |
| [MSTEST0020](mstest0020.md) | Prefer constructors over TestInitialize | None (opt-in) | Yes |
| [MSTEST0021](mstest0021.md) | Prefer Dispose over TestCleanup | None (opt-in) | Yes |
| [MSTEST0022](mstest0022.md) | Prefer TestCleanup over Dispose | None (opt-in) | Yes |
| [MSTEST0025](mstest0025.md) | Prefer Assert.Fail over always-false conditions | Info | Yes |
| [MSTEST0029](mstest0029.md) | Public method should be test method | Info | Yes |
| [MSTEST0036](mstest0036.md) | Do not use shadowing | Warning | No |
| [MSTEST0044](mstest0044.md) | Prefer TestMethod over DataTestMethod | Info | Yes |
| [MSTEST0045](mstest0045.md) | Use cooperative cancellation for timeout | Info | Yes |
| [MSTEST0004](mstest0004.md) | Public types should be test classes. | Info | Yes |
| [MSTEST0006](mstest0006.md) | Avoid ExpectedException attribute. | Info | Yes |
| [MSTEST0015](mstest0015.md) | Test method should not be ignored. | None (opt-in) | No |
| [MSTEST0016](mstest0016.md) | Test class should have test method. | Info | No |
| [MSTEST0019](mstest0019.md) | Prefer TestInitialize over constructors. | None (opt-in) | Yes |
| [MSTEST0020](mstest0020.md) | Prefer constructors over TestInitialize. | None (opt-in) | Yes |
| [MSTEST0021](mstest0021.md) | Prefer Dispose over TestCleanup. | None (opt-in) | Yes |
| [MSTEST0022](mstest0022.md) | Prefer TestCleanup over Dispose. | None (opt-in) | Yes |
| [MSTEST0025](mstest0025.md) | Prefer Assert.Fail over always-false conditions. | Info | Yes |
| [MSTEST0029](mstest0029.md) | Public method should be test method. | Info | Yes |
| [MSTEST0036](mstest0036.md) | Do not use shadowing. | Warning | No |
| [MSTEST0044](mstest0044.md) | Prefer TestMethod over DataTestMethod. | Info | Yes |
| [MSTEST0045](mstest0045.md) | Use cooperative cancellation for timeout. | Info | Yes |

## Common scenarios

### Test class structure

When creating test classes, these rules help ensure proper design:

- **[MSTEST0004](mstest0004.md)**: Keep helper classes internal, only test classes should be public
- **[MSTEST0016](mstest0016.md)**: Ensure test classes contain at least one test method
- **[MSTEST0029](mstest0029.md)**: Public methods in test classes should be test methods
- **[MSTEST0004](mstest0004.md)**: Keep helper classes internal, only test classes should be public.
- **[MSTEST0016](mstest0016.md)**: Ensure test classes contain at least one test method.
- **[MSTEST0029](mstest0029.md)**: Public methods in test classes should be test methods.

### Initialization patterns

MSTest supports both constructors and TestInitialize methods. These mutually exclusive rules let you enforce a consistent pattern:

- **[MSTEST0019](mstest0019.md)**: Enforce TestInitialize for initialization (useful for async scenarios)
- **[MSTEST0020](mstest0020.md)**: Enforce constructors for initialization (better for readonly fields)
- **[MSTEST0019](mstest0019.md)**: Enforce TestInitialize for initialization (useful for async scenarios).
- **[MSTEST0020](mstest0020.md)**: Enforce constructors for initialization (better for readonly fields).

### Cleanup patterns

Similarly, choose between Dispose and TestCleanup:

- **[MSTEST0021](mstest0021.md)**: Enforce Dispose pattern for cleanup
- **[MSTEST0022](mstest0022.md)**: Enforce TestCleanup for cleanup
- **[MSTEST0021](mstest0021.md)**: Enforce Dispose pattern for cleanup.
- **[MSTEST0022](mstest0022.md)**: Enforce TestCleanup for cleanup.

### Better assertions

- **[MSTEST0006](mstest0006.md)**: Use Assert.ThrowsExactly instead of [ExpectedException] for better precision
- **[MSTEST0025](mstest0025.md)**: Use Assert.Fail instead of Assert.IsTrue(false)
- **[MSTEST0006](mstest0006.md)**: Use Assert.ThrowsExactly instead of [ExpectedException] for better precision.
- **[MSTEST0025](mstest0025.md)**: Use Assert.Fail instead of Assert.IsTrue(false).

### Test quality

- **[MSTEST0015](mstest0015.md)**: Flag ignored tests (opt-in rule)
- **[MSTEST0036](mstest0036.md)**: Avoid shadowing base class members
- **[MSTEST0044](mstest0044.md)**: Use TestMethod unless data-driven testing is needed
- **[MSTEST0045](mstest0045.md)**: Enable cancellation tokens for timeout handling
- **[MSTEST0015](mstest0015.md)**: Flag ignored tests (opt-in rule).
- **[MSTEST0036](mstest0036.md)**: Avoid shadowing base class members.
- **[MSTEST0044](mstest0044.md)**: Use TestMethod unless data-driven testing is needed.
- **[MSTEST0045](mstest0045.md)**: Enable cancellation tokens for timeout handling.

## Related documentation

Expand Down
4 changes: 2 additions & 2 deletions docs/core/testing/mstest-analyzers/performance-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Performance rules support high-performance testing by identifying opportunities

| Rule ID | Title | Severity | Fix Available |
|---------|-------|----------|---------------|
| [MSTEST0001](mstest0001.md) | Use Parallelize attribute | Info | Yes |
| [MSTEST0001](mstest0001.md) | Use Parallelize attribute. | Info | Yes |

## Common scenarios

### Test parallelization

By default, MSTest runs tests sequentially, which can significantly impact execution time for large test suites.

- **[MSTEST0001](mstest0001.md)**: Reminds you to explicitly enable parallelization with `[assembly: Parallelize]` or acknowledge sequential execution with `[assembly: DoNotParallelize]`
- **[MSTEST0001](mstest0001.md)**: Reminds you to explicitly enable parallelization with `[assembly: Parallelize]` or acknowledge sequential execution with `[assembly: DoNotParallelize]`.

**Why this matters**: Parallelization can dramatically reduce test execution time by running tests concurrently across multiple threads or processes. However, not all test suites are safe to parallelize (for example, tests that modify shared state). This rule ensures you make a conscious decision about parallelization.

Expand Down
6 changes: 3 additions & 3 deletions docs/core/testing/mstest-analyzers/suppression-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Suppression rules automatically suppress diagnostics from other analyzers (like

| Rule ID | Title | Suppresses |
|---------|-------|------------|
| [MSTEST0027](mstest0027.md) | Suppress async suffix for test methods | VSTHRD200 |
| [MSTEST0028](mstest0028.md) | Suppress async suffix for test fixture methods | VSTHRD200 |
| [MSTEST0033](mstest0033.md) | Suppress non-nullable reference not initialized | CS8618 |
| [MSTEST0027](mstest0027.md) | Suppress async suffix for test methods. | VSTHRD200 |
| [MSTEST0028](mstest0028.md) | Suppress async suffix for test fixture methods. | VSTHRD200 |
| [MSTEST0033](mstest0033.md) | Suppress non-nullable reference not initialized. | CS8618 |

## How suppression rules work

Expand Down
Loading