qshinoの日記

Powershell関係と徒然なこと

Pester

Pester for PowerShell

実行方法

雛形生成
New-Fixture .\bin Code

テスト実行
Invoke-Pester .\bin\Code.Tests.ps1

テスト記法

Describe "Code" {
  Context "poi1" {
    It "Test Case 1" {
      $data | should Be $null
    }
    It "TestCase2" {
      "" | Should exist
    }
  }
  Context "poi2"
    It "poiqwe case 1" {
      "file.txt" | should contain "John"
    }
    It "poiqwe case 2" {
      "$x" | should BeNullOrEmpty
    }
  }
}

他の動詞

- match REGEX
- throw

TestDrive例

function Add-Footer($path, $footer) {
    Add-Content $path -Value $footer
}

Describe "Add-Footer" {
    $testPath = "TestDrive:\test.txt"
    Set-Content $testPath -value "my test text."
    Add-Footer $testPath "-Footer"
    $result = Get-Content $testPath

    It "adds a footer" {
        (-join $result) | Should Be "my test text.-Footer"
    }
}

参考

https://github.com/pester/Pester/wiki/Pester

http://softwaretest.jp/labo/tech/labo-300/

http://blog.nakajix.jp/entry/2013/12/26/005443