Powershell Unit test
ユニットテストツール
Pesterの紹介
PeaterはPowerShell向けのUnit Test Tool
使い方
PS> New-Fixture -Name HelloWorld
これで、HelloWorld.ps1と、HelloWorld.Tests.ps1が作成される。
実行は
PS> invoke-pester
Executing all tests in 'C:\usr\tmp'
Describing HelloWorld
[-] does something useful 1.13s
Expected: {False}
But was: {True}
at line: 7 in C:\usr\tmp\HelloWorld.Tests.ps1
Tests completed in 1.13s
Passed: 0 Failed: 1
HelloWorld.Tests.ps1は、
Describe "HelloWorld" {
It "does something useful" {
$true | Should Be $false
}
}
HelloWorld.ps1は、
function HelloWorld {
}
sholdの後の述語
Be VALUE : 期待値 VALUE
Match REGEXP
it の文法
it “test name” { FUNC | sholud VERB }
参考
https://www.simple-talk.com/sysadmin/powershell/practical-powershell-unit-testing-getting-started/