Skip to content

Commit 2ec3287

Browse files
authored
Update Pester test guidance in community style guidelines (dsccommunity#2444)
1 parent f8f557d commit 2ec3287

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.github/instructions/dsc-community-style-guidelines-pester.instructions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,26 @@ applyTo: "**/*.[Tt]ests.ps1"
3939

4040
## Syntax Rules
4141
- PascalCase: `Describe`, `Context`, `It`, `Should`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach`
42-
- Use `-BeTrue`/`-BeFalse` never `-Be $true`/`-Be $false`
42+
- Use `-BeTrue`/`-BeFalse` never `-Be $true`/`-Be $false`/`-Contain $true`/`-Contain $false`
4343
- Never use `Assert-MockCalled`, use `Should -Invoke` instead
4444
- No `Should -Not -Throw` - invoke commands directly
4545
- Never add an empty `-MockWith` block
4646
- Omit `-MockWith` when returning `$null`
4747
- Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
4848
- Omit `-ModuleName` parameter on Pester commands
4949
- Never use `Mock` inside `InModuleScope`-block
50-
- Never use `param()` inside `-MockWith` scriptblocks, parameters are auto-bound
50+
- Never use `param()`-block inside `-MockWith` scriptblocks, parameters are auto-bound
51+
- In `InModuleScope` tests, add `Set-StrictMode -Version 1.0` immediately before invoking the tested function
52+
- Use `Should -Invoke -Exactly -Times <n> -Scope It` for call-count assertions
53+
- Assert <n> calls inside the `It` block; do not assert call counts across an entire `Describe` or `Context`
5154

5255
## File Organization
5356
- Class resources: `tests/Unit/Classes/{Name}.Tests.ps1`
5457
- Public commands: `tests/Unit/Public/{Name}.Tests.ps1`
5558
- Private functions: `tests/Unit/Private/{Name}.Tests.ps1`
5659

5760
## Data-Driven Tests (Test Cases)
58-
- Define `-ForEach` variables in `BeforeDiscovery` (close to usage)
61+
- Define `-ForEach` variables in separate `BeforeDiscovery` (close to usage)
5962
- `-ForEach` allowed on `Context` and `It` blocks
6063
- Never add `param()` inside Pester blocks when using `-ForEach`
6164
- Access test case properties directly: `$PropertyName`

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Changed
9+
10+
- SqlServerDsc
11+
- Updated Pester test guidance in AI instructions in community style guidelines.
12+
813
## [17.5.0] - 2026-01-30
914

1015
### Changed

0 commit comments

Comments
 (0)