New to pester 5, Getting started, and design decisions behind v5? #2087
-
Thanks everyone that puts work into Pester, we use it at $OfficialJob for Infrastructure tests (For $Reasons), mostly ver 3, a bit of 4 even in an Azure Devops Pipeline. I'm finding ver 5 very difficult to wrap my head around. Most of the details I think are hidden away in the documentation, but are more hinted at rather than explicit:
Thanks for any pointers, etc. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, thanks for the questions:
There are multiple features that discovery enables. Most importantly it's being able to run single test, or a group of tests in a file or multiple files without having to run all setups around it. This is not very useful for CI runs, but is valuable for interactive runs, for example in VSCode where the Test UI can first do Discovery only, figure out what tests are there without actually running them and you can then choose what to run. I agree data driven tests are more complicated than before. The scopes are not very complicated though. The scriptblocks that you provide to It, BeforeAll, BeforeEach, AfterEach and AfterAll are all run during Run. Everything else, that is: code in the script directly, code in the body of Describe, code in the body of Context, code in BeforeDiscovery and also parameters. Most notably -Foreach (-TestCases) are also evaluated during Discovery.
Container in Pester is just this: @{
Type = "File"
Item = "C:\tests\My.Tests.ps1"
Data = @{
Name = "Jakub"
}
} A path to a file (or a scriptblock) that has test code in it, and a hashtable that has data for those tests. What might confuse you is that you can provide multiple paths, and multiple hashtables to New-PesterContainer. This is just for convenience, when this object is received by Pester it will "multiply" the data, to end up with multiple objects each having only 1 path and only 1 hashtable of data:
You would want to use it when you provide data to your tests, especially when you provide the same set of tests to multiple files, or all files in a given directory. You can also use it to provide a scriptblock if you want a self-contained example that just runs (we use this extensively in testing Pester). Also you are already using container every time you use Pester. When you provide -Path, it is internally translated to a container with no data.
Configuration is a different thing all together. Configuration contains everything that can be configured in Pester, and is internally used everywhere. Configuration, takes Container in the Run section. And it also takes Path, and ScriptBlock, all three are internally converted to Container.
Containers are required to pass data to tests, but you can do everything inline if you want, for example this is how you'd run all test files with the given data:
There could also be a convenience syntax |
Beta Was this translation helpful? Give feedback.
Hello, thanks for the questions:
There are multiple features that discovery enables. Most importantly it's being able to run single test, or a group of tests in a file or multiple files without having to run all setups around it. This is not very useful for CI runs, but is valuable for interactive runs, for example in VSCode where the Test UI can first do Discovery only, figure out what tests are there without actually running them and you can then choose what to run.
I agree data driven tests are more complicated than before. The scopes are not very complicated though. The scriptblocks that you provide to It, BeforeAll, BeforeEach, Afte…