Created
November 28, 2016 05:53
-
-
Save stknohg/f2eda93273abc4f5a21468f52cd5b868 to your computer and use it in GitHub Desktop.
Pesterでパラメタライズドテストを行うサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <Target> の結果が <Expected> になること" -TestCases $testCases { | |
param($Target, $Expected) | |
FizzBuzz $Target | Should Be $Expected | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブログにもまとめています。