{{ message }}

Instantly share code, notes, and snippets.

# stknohg/Invoke-PesterParameterizedTestSample.ps1

Created Nov 28, 2016
Pesterでパラメタライズドテストを行うサンプル
 Import-Module Pester # テスト用の適当な関数 function FizzBuzz([int]\$Value) { if (\$Value -le 0) { return "Error!" } if (\$Value % 15 -eq 0) { return "FizzBuzz" } if (\$Value % 3 -eq 0) { return "Fizz" } if (\$Value % 5 -eq 0) { return "Buzz" } return \$Value.ToString() } Describe "パラメタライズドテストのサンプル" { \$testCases = @( @{Target = 0; Expected = "Error!"}; @{Target = 1; Expected = "1"}; @{Target = 2; Expected = "2"}; @{Target = 3; Expected = "Fizz"}; @{Target = 4; Expected = "4"}; @{Target = 5; Expected = "Buzz"}; @{Target = 6; Expected = "Fizz"}; @{Target = 7; Expected = "7"}; @{Target = 8; Expected = "8"}; @{Target = 9; Expected = "Fizz"}; @{Target = 10; Expected = "Buzz"}; @{Target = 15; Expected = "FizzBuzz"}; ) It "FizzBuzz の結果が になること" -TestCases \$testCases { param(\$Target, \$Expected) FizzBuzz \$Target | Should Be \$Expected } }

### stknohg commented Mar 9, 2017

 ブログにもまとめています。