Skip to content

5.1.0

Compare
Choose a tag to compare
@nohwnd nohwnd released this 25 Nov 10:19

5.1.0

First of all, huge thanks to @fflaten who contributed a huge amount of code, bug fixing, issue responses, and improvements in this and previous releases. 🍾🥂

Also thanks to all other contributors who contributed by reporting and fixing bugs, posting PRs, discussing features, or just by sharing their opinion.

Catching up with v4

Parametrized scripts

Passing parameters to scripts works again. Read all about it, and how to generate tests in https://pester.dev/docs/usage/data-driven-tests.

New-Fixture is back

New-Fixture was added back into Pester v5, with a better behavior. It will now fail by default to show you that you did not complete the template.

Updated help

Help was updated both on function and in the usage docs on Pester docs site, including sections specific for migrating from Pester v4. See:

JUnit output is working again

JUnit output for Pester results is available again. And NUnit output is fixed.

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

See https://pester.dev/docs/usage/data-driven-tests for even more info on this.

Smaller improvements

  • Add missing and update help for exported functions #1785
  • Add JUnit XML output #1748
  • Always set exit code exit #1734
  • Print active filters in Detailed/Diagnostic output #1727
  • Re-implement New-Fixture in Pester v5 #1726
  • Add support for VSCode problem-tracking for failed assertions #1700
  • Allow AfterAll in top-level #1707
  • Throw when legacy syntax is used #1706
  • Remove pipeline support from Should -Invoke #1698
  • 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 devcontainer to project #1661
  • Parametric scripts #1671

See full log here