github pester/Pester 5.1.0-beta1

latest releases: 6.0.0-alpha5, 6.0.0-alpha4, 6.0.0-alpha3...
pre-release4 years ago

New features

BeforeDiscovery block

BeforeDiscovery is a semantic block that allows you to group your code together if you need it to run during discovery. It just takes your code and runs it in place. But it gives a nice way of showing that this code is here intentionally, and not just a forgotten piece of code that you did not migrate to Pester v5.

BeforeDiscovery { 
    $testConfigs = Get-ChildItem -Path $PSScriptRoot/TestConfigs
}

Describe "Platform dependent tests" {
    foreach ($config in $testConfigs) {
        It "Runs for config $($config.Name)" { 
            # ...
        }
    }
}

"TestCases" for Describe and Context

-ForEach parameter was added to Describe and Context, and also to It as an alias for -TestCases. Like -TestCases on It you can use this to create one block for each example.

This has been long awaited and this thread has a lot of examples of the usage. #1679

This can also be used with the parameters that you provide directly to the script which was introduced in the previous preview. See example of the usage in the thread. #1679 (comment)

"TestCases" can take any array, not just arrays of hashtables

You can now provide any array to -TestCases / -ForEach, and it will be defined as $_ in your tests. Additionally if your array is an array of hashtables, each key in that hashtable will be expanded to a variable, the same way it already works for -TestCases.

(Just don't use _ as the name of any Key in your hashtable, it won't work well.

Templates expand to all variables and allow dot-notation

Using this syntax <user>, that you know from -TestCases you can now expand value from any variable that is defined in the scope, not just from the provided hashtable. You can use <_> to expand the $_. You can also use dot-notation <user.name>, to navigate into the object. Here an example of the dot-notation in action:

Describe "<animal.name>" -ForEach @(
    @{
        Animal = @{
            Name = "dog"
            Sounds = @("woof", "barf")
        }
    }
    @{
        Animal = @{
            Name = "cat"
            Sounds = @("meow", "purr")
        }
    }
    ) {

    It "<animal.name> goes <_>" -ForEach $Animal.Sounds {

    }
}
Starting discovery in 1 files.
Discovering in C:\Users\jajares\Desktop\ex.tests.ps1.
Found 4 tests. 48ms
Discovery finished in 61ms.

Running tests from 'C:\Users\jajares\Desktop\ex.tests.ps1'
Describing dog
  [+] dog goes woof 10ms (4ms|5ms)
  [+] dog goes barf 11ms (2ms|8ms)

Describing cat
  [+] cat goes meow 8ms (2ms|7ms)
  [+] cat goes purr 8ms (5ms|3ms)
Tests completed in 370ms

Issues Fixed

  • Filter excluded tests from NUnit results #1686
  • Add -ForEach parameter to Describe, Context, and as an alias to -Test… #1681
  • Add BeforeDiscovery semantic block #1680
  • Add fallback startline #1678

See full log here

Don't miss a new Pester release

NewReleases is sending notifications on new releases.