Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 <Target> の結果が <Expected> になること" -TestCases $testCases {
param($Target, $Expected)
FizzBuzz $Target | Should Be $Expected
}
}
@stknohg

This comment has been minimized.

Copy link
Owner Author

@stknohg stknohg commented Mar 9, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment