Skip to content

Commit 4ac78d9

Browse files
committed
Enhance test execution instructions with detailed PowerShell configuration for code coverage
1 parent 49b3ec1 commit 4ac78d9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@ Always run build script from root path.
2121

2222
### Run tests
2323

24-
Always build project prior to running tests.
25-
Always run `Invoke-Pester` from root path.
26-
After adding or changing classes, always run tests in new session.
27-
28-
- To run tests, always run `.\build.ps1 -Tasks noop` or `.\build.ps1 -Tasks build` prior to running `Invoke-Pester`.
29-
- To run single test file, always run `.\build.ps1 -Tasks noop` together with `Invoke-Pester`,
30-
e.g `.\build.ps1 -Tasks noop;Invoke-Pester -Path '<test path>' -Output Detailed`
31-
- `.\build.ps1 -Tasks test` which will run all QA and unit tests in the project
32-
with code coverage. Add `-CodeCoverageThreshold 0` to disable code coverage, e.g.
33-
`.\build.ps1 -Tasks test -CodeCoverageThreshold 0`.
24+
- Always use PowerShell or Windows PowerShell to run tests.
25+
- Always build project prior to running tests: `.\build.ps1 -Tasks build`
26+
- Always run `Invoke-Pester` from root path: `Invoke-Pester -Path @('<test paths>') -Output Detailed`
27+
- After adding or changing classes, always run tests in new session.
28+
- To run a test file with code coverage (this can takes a while for large codebases):
29+
```powershell
30+
$config = New-PesterConfiguration
31+
$config.Run.Path = @('<test paths>')
32+
$config.CodeCoverage.Enabled = $true
33+
$config.CodeCoverage.Path = @('./output/builtModule/<ModuleName>')
34+
$config.CodeCoverage.CoveragePercentTarget = 0
35+
$config.Output.Verbosity = 'Detailed'
36+
$config.Run.PassThru = $true
37+
$result = Invoke-Pester -Configuration $config
38+
# After running above, get all commands that was missed with a reference to the SourceLineNumber in SourceFile.
39+
$result.CodeCoverage.CommandsMissed | Where-Object { $_.Function -eq '<FunctionName>' -or $_.Class -eq '<ClassName>' } | Convert-LineNumber -PassThru | Select-Object Class, Function, Command, SourceLineNumber, SourceFile
40+
```
3441

3542
## Change log
3643

0 commit comments

Comments
 (0)