You are on page 1of 4

Each It block should test one thing and throw an exception if the test

fails. Pester will consider any It block that throws an exception to be a


failed test. Pester provides a set of extensions that can perform various
comparisons between the values emitted or altered by a test and an expected
value (see about_Should).

RUNNNING A PESTER TEST


Once you have some logic that you are ready to test, run the Tests file
directly,
usually by pressing F5 in your ISE.

To run multiple test files, get summary for the test run, to get nUnit
compatible XML
report or to get PesterResult object use the Invoke-Pester command. You can
zero in on
just one test (Describe block) or an entire tree of directories.

function BuildIfChanged {
# Please note that <errata@unicode.org> is an archival address;
# notices will be checked, but do not expect an immediate response.
0x9C 0x009C # <control>
0x9D 0x009D # <control>
0x9E 0x009E # <control>
0x9F 0x009F # <control>
0xA0 0x00A0 # NO-BREAK SPACE
0xA2 0x00A2 # CENT SIGN
0xA3 0x00A3 # POUND SIGN
0xA4 0x00A4 # CURRENCY SIGN
0xA5 0x00A5 # YEN SIGN
0xA6 0x00A6 # BROKEN BAR
0xA7 0x00A7 # SECTION SIGN
0xA8 0x00A8 # DIAERESIS
0xA9 0x00A9 # COPYRIGHT SIGN
0xAA 0x00D7 # MULTIPLICATION SIGN
0xAB 0x00AB # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
Each It block should test one thing and throw an exception if the test
fails. Pester will consider any It block that throws an exception to be a
failed test. Pester provides a set of extensions that can perform various
comparisons between the values emitted or altered by a test and an expected
value (see about_Should).

RUNNNING A PESTER TEST


Once you have some logic that you are ready to test, run the Tests file
directly,
usually by pressing F5 in your ISE.

To run multiple test files, get summary for the test run, to get nUnit
compatible XML
report or to get PesterResult object use the Invoke-Pester command. You can
zero in on
just one test (Describe block) or an entire tree of directories.

function BuildIfChanged {
# The entries are in ISO/IEC 8859-8 order.
#
# Version history
# 1.0 version updates 0.1 version by adding mappings for all
# control characters.
# 1.1 version updates to the published 8859-8:1999, correcting
# the mapping of 0xAF and adding mappings for LRM and RLM.
#
# Updated versions of this file may be found in:
# <ftp://ftp.unicode.org/Public/MAPPINGS/>
#
# Any comments or problems, contact <errata@unicode.org>
# Please note that <errata@unicode.org> is an archival address;
# notices will be checked, but do not expect an immediate response.
0xED 0x05DD # HEBREW LETTER FINAL MEM
0xEE 0x05DE # HEBREW LETTER MEM
0xEF 0x05DF # HEBREW LETTER FINAL NUN
0xF0 0x05E0 # HEBREW LETTER NUN
0xF1 0x05E1 # HEBREW LETTER SAMEKH
0xF2 0x05E2 # HEBREW LETTER AYIN
0xF3 0x05E3 # HEBREW LETTER FINAL PE
0xF4 0x05E4 # HEBREW LETTER PE
0xF5 0x05E5 # HEBREW LETTER FINAL TSADI
0xF6 0x05E6 # HEBREW LETTER TSADI
0xF7 0x05E7 # HEBREW LETTER QOF
0xF8 0x05E8 # HEBREW LETTER RESH
0xF9 0x05E9 # HEBREW LETTER SHIN
0xFA 0x05EA # HEBREW LETTER TAV
0xFD 0x200E # LEFT-TO-RIGHT MARK
0xFE 0x200F # RIGHT-TO-LEFT MARK

Creates two files:


./deploy/Clean.ps1
function clean {

./deploy/clean.Tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.',
'.'
. "$here\$sut"

Describe "clean" {

It "does something useful" {


$true | should be $false
}
}

Now you have a skeleton of a clean function with a failing test. Pester
considers all files containing *Tests.ps1 to be a test file (see
Invoke-Pester) and by default it will look for these files and run all
Describe blocks inside the file (See Describe). The Describe block can
contain several behavior validations expressed in It blocks (see It).
Each It block should test one thing and throw an exception if the test
fails. Pester will consider any It block that throws an exception to be a
failed test. Pester provides a set of extensions that can perform various
comparisons between the values emitted or altered by a test and an expected
# <ftp://ftp.unicode.org/Public/MAPPINGS/>
#
# Any comments or problems, contact <errata@unicode.org>
# Please note that <errata@unicode.org> is an archival address;
# notices will be checked, but do not expect an immediate response.
0xED 0x05DD # HEBREW LETTER FINAL MEM
0xEE 0x05DE # HEBREW LETTER MEM
0xEF 0x05DF # HEBREW LETTER FINAL NUN
0xF0 0x05E0 # HEBREW LETTER NUN
0xF1 0x05E1 # HEBREW LETTER SAMEKH
0xF2 0x05E2 # HEBREW LETTER AYIN
0xF3 0x05E3 # HEBREW LETTER FINAL PE
0xF4 0x05E4 # HEBREW LETTER PE
0xF5 0x05E5 # HEBREW LETTER FINAL TSADI
0xF6 0x05E6 # HEBREW LETTER TSADI
0xF7 0x05E7 # HEBREW LETTER QOF
0xF8 0x05E8 # HEBREW LETTER RESH
}

$here = Split-Path -Parent $MyInvocation.MyCommand.Path


$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.',
'.'
. "$here\$sut"

Describe "BuildIfChanged" {
Context "When there are Changes" {
Mock Get-Version {return 1.1}
Mock Get-NextVersion {return 1.2}
Mock Build {} -Verifiable -ParameterFilter {$version -eq 1.2}

$result = BuildIfChanged

It "Builds the next version" {


Assert-VerifiableMocks
}
It "returns the next version number" {
$result | Should Be 1.2
}
}
Context "When there are no Changes" {
Mock Get-Version -MockWith {return 1.1}
Mock Get-NextVersion -MockWith {return 1.1}
Mock Build {}

$result = BuildIfChanged
# <ftp://ftp.unicode.org/Public/MAPPINGS/>
#
# Any comments or problems, contact <errata@unicode.org>
# Please note that <errata@unicode.org> is an archival address;
# notices will be checked, but do not expect an immediate response.
0xED 0x05DD # HEBREW LETTER FINAL MEM
0xEE 0x05DE # HEBREW LETTER MEM
0xEF 0x05DF # HEBREW LETTER FINAL NUN
0xF0 0x05E0 # HEBREW LETTER NUN
0xF1 0x05E1 # HEBREW LETTER SAMEKH
0xF2 0x05E2 # HEBREW LETTER AYIN
0xF3 0x05E3 # HEBREW LETTER FINAL PE
0xF4 0x05E4 # HEBREW LETTER PE
0xF5 0x05E5 # HEBREW LETTER FINAL TSADI
0xF6 0x05E6 # HEBREW LETTER TSADI
0xF7 0x05E7 # HEBREW LETTER QOF
0xF8 0x05E8 # HEBREW LETTER RESHnce Batch file:

<Target Name="Tests">
<Exec Command="cmd /c $(baseDir)pester\bin\pester.bat" />
</Target>

This will start a PowerShell session, import the Pester Module and call
invoke pester within the current directory. If any test fails, it will
return an exit code equal to the number of failed tests and all test
results will be saved to Test.xml using NUnit's Schema allowing you to
plug these results nicely into most Build systems like CruiseControl,
TeamCity, TFS or Jenkins.

# <ftp://ftp.unicode.org/Public/MAPPINGS/>
#
# Any comments or problems, contact <errata@unicode.org>
# Please note that <errata@unicode.org> is an archival address;
# notices will be checked, but do not expect an immediate response.
0xED 0x05DD # HEBREW LETTER FINAL MEM
0xEE 0x05DE # HEBREW LETTER MEM
0xEF 0x05DF # HEBREW LETTER FINAL NUN
0xF0 0x05E0 # HEBREW LETTER NUN
0xF1 0x05E1 # HEBREW LETTER SAMEKH
0xF2 0x05E2 # HEBREW LETTER AYIN
0xF3 0x05E3 # HEBREW LETTER FINAL PE
0xF4 0x05E4 # HEBREW LETTER PE
0xF5 0x05E5 # HEBREW LETTER FINAL TSADI
0xF6 0x05E6 # HEBREW LETTER TSADI
0xF7 0x05E7 # HEBREW LETTER QOF
0xF8 0x05E8 # HEBREW LETTER RESH
Invoke-Pester
about_Should
about_TestDrive

You might also like