Skip to content

Commit

Permalink
Add [ExcludeFromCodeCoverageAttribute()] (#338)
Browse files Browse the repository at this point in the history
* Add [ExcludeFromCodeCoverageAttribute()]

* Update docs/usage/code-coverage.mdx
  • Loading branch information
nohwnd authored Jan 16, 2025
1 parent 8b2ff42 commit 4c9b245
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/usage/code-coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ CoverageTest.ps1 FunctionTwo 16 return 'I do not'
As you can see, the test script fails to run `FunctionOne` with its switch parameter set,
and there is an unreachable line of code in `FunctionTwo`.

### Excluding functions from coverage

To exclude a function (or scriptblock) from code coverage. Place `[ExcludeFromCodeCoverageAttribute()]` before the param block of the function:

```powershell
function FunctionExcluded {
[ExcludeFromCodeCoverageAttribute()]
param()
"I am not included"
}
```

## Coverage Format

By default, Pester generates a `coverage.xml` file in [JaCoCo](https://www.jacoco.org/) format. You have the flexibility to modify the output format, path, and encoding by using the following options:
Expand Down Expand Up @@ -214,4 +226,4 @@ To integrate Pester tests with Code Coverage into your GitHub Actions workflow,
4. Adjust the paths and configurations in the workflow according to your project structure and requirements.
With this configuration, Pester tests will be executed with Code Coverage, and the coverage report will be available as an artifact in your GitHub Actions workflow.
With this configuration, Pester tests will be executed with Code Coverage, and the coverage report will be available as an artifact in your GitHub Actions workflow.

0 comments on commit 4c9b245

Please sign in to comment.