Releases: pester/Pester
4.3.1
What is new since 4.2.0
- Improved output, that expands $true, $false, $null, collections, dates and so on, to make the results of assertions, and test case expansions much easier to read.
Describing new assertion output
[-] strings now have single quotes like 'this' 63ms
Expected strings to be the same, but they were different.
String lengths are both 4.
Strings differ at index 0.
Expected: ' abc'
But was: 'abc '
-----------^
5: 'abc ' | Should -Be " abc"
[-] empty string and null became <empty> and $null 36ms
Expected <empty>, but got $null.
9: $null | Should -Be ''
[-] numbers have nothing around them 30ms
Expected 0, but got 1.
13: 1 | Should -Be 0
[-] decimals and doubles use point 0.1 45ms
Expected 0, but got 0.1.
17: 0.1 | Should -Be 0
[-] booleans are written as $true and $false 71ms
Expected $false, but got $true.
21: $true | Should -Be $false
[-] dates are expanded to include ticks 83ms
Expected 0001-01-01T00:00:00.0000000, but got 2018-02-20T18:39:15.7773648+01:00.
25: (Get-Date) | Should -Be ([datetime]::MinValue)
[-] collections are wrapped in @() 49ms
Expected an empty collection, but got collection with size 3 @(1, 2, 3).
- There are now tests that make sure that we have comprehensive help.
(The version 4.3.0 was briefly published, but dependencies were missing from the package, so a new version had to be published. That is why this is both minor and patch bump.)
Breaking changes
- None, unless you depend on the exact wording of our assertion messages.
4.2.0
This release focuses primarily on making assertions better, even thought there are other small fixes and updates.
What's new since 4.1.1:
New assertions
-
There are now
Should -BeLessThan
andShould -BeLessOrEqual
assertions to complement the existingBeGreaterThan
andBeGreaterOrEqual
assertions. -
Should -Contain
assertion was added that operates on collections, the same way the-contains
operator operates on them.
1,2,3 | Should -Contain 1
Should -HaveCount
was added that counts items in a collection
1,2,3 | Should -HaveCount 3
Should -BeTrue
andShould -BeFalse
were added to assert on truthy and falsy values
$true | Should -BeTrue
1 | Should -BeTrue
$false | Should -BeFalse
0 | Should -BeFalse
Assertion improvements
- Every built in assertion allows you to specify
-Because
parameter, to give more meaning to your tests.
function Get-Group { $null }
$groups = 1..10 | Get-Group -Size 3
$groups | Should -HaveCount 4
`-Because "because 10 items are split into three groups with 3 members and one extra group with 1 member"
Which fails with:
Expected a collection with size {4},
because 10 items are split into three groups with 3 members and one extra group with 1 member,
but got collection with size {1} [].
Should -Throw
has-ExceptionType
parameter that matches the exception type and any of its subtypes.
function a () { throw [System.ArgumentNullException]"argument is null" }
# this passes because, ArgumentNullException inherits from ArgumentException
{ a } | Should -Throw -ExceptionType ([ArgumentException])
# this fails, because ArgumentNullExcption does not inherit from InvalidOperationException
{ a } | Should -Throw -ExceptionType ([InvalidOperationException])
Should -Throw
has-PassThru
parameter that returns the caputed exception to output. This is useful for catching a complex exception and further inspecting it.
$err = {
throw (New-Object System.InvalidOperationException "Something wrong happened",
(New-Object DivideByZeroException "you divided by zero")
)
} | Should -Throw -PassThru
$err.Exception.InnerException.Message | Should -Be "you divided by zero"
Should -BeOfType
is now aliased to-HaveType
1 | Should -HaveType [int]
Breaking changes:
Should -Not -Throw
will fail if any exception is thrown. The filters applied onShould -Not -Throw
do not apply, because when an exception is thrown, it automatically means that the test should not pass.
4.1.1
4.1.0
What's new since 4.0.8:
- Pester now runs on Linux and macOS! 🎉 🍾 Big thanks to @it-praktyk for making it possible.
- There are some limitations when running Linux and macOS (or more broadly speaking on PSCore), go here to learn more.
Breaking changes:
- Minor release is not a good place to introduce breaking changes, but we had to do it anyway, sorry. The progress bar is no longer used to show which test is running. The other output works as before. The reason to remove the progress bar was that it causes performance issues (huge ones on TravisCI). A replacement functionality, that will be less flashy, and more CI friendly will be introduced soon. To track status see #939.
4.0.8
Function Assert-VerifiableMocks
that throws an exception is added back to Pester to avoid loading older version of the module and failing with a cryptic message.
4.0.7
There is a guide for migrating from Pester 3 to Pester 4 to help you understand how the changes from Pester 3 to Pester 4 might affect your tests.
What's new since 3.4.6:
- Nested
Describe{}
andContext{}
. Now you can group tests using as manyContexts{}
andDescribe{}
blocks in any order. The use of mocks inDescribe{}
andContext{}
blocks nested deeper than one of each is still unexplored territory, so proceed with an appropriate amount of caution. The same goes for-Tag
, it only works on the top-levelDescribe/Context
. - Improved and color-coded summaries output by
Invoke-Pester
. No more misreading that all your tests are failed! Invoke-Pester
now includes the name of the script it is currently executing. No more guessing which file a failed test is in!- New assertion syntax with assertions as parameters to
Should
, that allows richer assertion vocabulary. Instead ofShould Not Be 10
you should writeShould -Not -Be 10
. - Custom
Should
operators. UseAdd-AssertionOperator
to write your own assertions. You could write an operator that allows you to write the working assertion$person | Should -BeAwesome
. - Array assertions.
Should
now inspects array contents. For example,1,2,3 | Should -Be 1,2,4
produces a user-friendly failure message. It even works recursively, so assertions like1,@(2,3) | Should -Be 1,@(2,4)
work. - Code coverage output in JaCoCo format. Use
Invoke-Pester
's-CodeCoverage
and-CodeCoverageOutputFile
parameters to produce code coverage reports that integrate with many CI tools. - Support for Gherkin.
- Smaller distribution package. Files not necessary for end-users are now omitted from Pester packages.
Breaking changes:
Contain*
assertions were renamed toFileContentMatch*
to avoid confusing its behavior with-contains
operator.Assert-VerifiableMocks
was renamed toAssert-VerifiableMock
Get-MockDynamicParameters
was renamed toGet-MockDynamicParameter
- Implementation of
Mock
changed significantly. That means you might observe some subtle differences in behavior. See the migration guide for more details.
Deprecated starting with 4.0.0:
- The
New-TestDriveItem
command has been deprecated. - The
-Quiet
parameter of theInvoke-Pester
command has been deprecated. Use-Show None
instead.
Removed starting with 4.0.0:
- The
-OutputXml
parameter of theInvoke-Pester
command was deprecated already, now it has been removed. Use-OutputFormat
and-OutputFile
instead.
v3.4.3
v3.4.2
v3.4.1
- Updated code to use Get-CimInstance if possible, then Get-WmiObject, for Nano compatibility. [GH-484]
- Fixed failure message output of Should BeLike / BeLikeExactly. [GH-497]
- Added some missing information to about_Should help. [GH-519]
- Made -OutputFormat parameter optional, defaulting to NUnitXml. [GH-503]
- Fix error messsage of Should Throw when null input is provided [GH-521]
- Fix mocking bug on functions that contain certain parameter names (Metadata, etc). [GH-583]
3.4.0
- Bug fix for PSv2 when no matching scripts are found by Invoke-Pester. [GH-441]
- Added "Should BeLike" assertion. [GH-456]
- Discarded unwanted pipeline output from BeforeEach / AfterEach / BeforeAll / AfterAll. [GH-468]
- Allowed closures to be used as mocks. [GH-465]
- Fixed invalid NUnit XML output if test script had a syntax error. [GH-467]
- Fix for mocking advanced functions that define a parameter named 'Args'. [GH-471]
- Fixed bug when trying to mock a command with a weird name containing a single quotation mark. [GH-474]
- Fixed bug for mocking Cmdlets that do not contain any positional parameters. [GH-477]
- Fixed bug when calling a mocked command from inside the mock. [GH-478]
- Added PesterOption parameter, and a switch to tweak console output for better VSCode extension functionality. [GH-479]