Use of Tags


Is it good practice to always provide a tag on tests? I’m thinking of using “unit” as a default tag on tests, and different tags (“integration”, “regression” etc) for non-unit tests. By default then invoking pester will run all tests, and I can run specific tests using IncludeTags. I realise I could get the same result using excludeTags but thinking being explicit with tags might provide a bit more flexibility.


Hi Dave,

It’s completely up to you to use tags or not. You mentioned tagging tests as “unit”. That’s possible but I, personally, create different files for unit/integration tests. It’s just a different way of grouping. People also use tags to indicate tests for different versions of PowerShell, different OSes, etc. There’s really no “recommended” way to use them that I know of.

Hi Adam. Thanks for the response. To add a bit more info, I’m working on a project that includes around 10 modules and dozens of functions. So I’m specifically referring to testing the entire project in one go rather than say just a single *.unit.tests.ps1 (or *.integration.tests.ps1) file.

So basically I’m trying to ensure I can easily test the whole solution, or if need just run all “unit” tests, or all “integration” tests. Do you find you can still easily achieve that my not using tags and separating the tests into unit/integration test files?


I’ve actually create a small framework around Pester tests that allow me to do things like Start-UnitTest, Start-IntegrationTest, etc. This allows me to have better control over things like you’re talking about.

Here’s a writeup I did on it.,1-3418.html

Ah, I see. So you’ve basically replaced the tags functionality with a more flexible way of invoking different tests or specific modules or functions. Nice.

In your Start-PesterTest function though, after you invoke Pester what is the purpose of the invoking it again with “$steppablePipeline.Begin”? (Lines 47-50).

That was from creating a proxy function. I’ve updated it since then. I should probably get that new code up there. :slight_smile: