Powershellの素晴らしいPesterユニットテストをしばらく使用して、私はゆっくりと習っています。関数に必須の入力がない場合、関数を実行できるかどうかのチェックの使い方については、まあまあです。私はここで赤い光を与えていて、緑のテスト結果を達成し、コーディングを進めたいと思っていました。Pesterユニットのテスト機能がMandatory = Trueの場合
私は次のような機能を持っています。私のテストスクリプトは、次のチェック で実行され
function Code()
{
param(
[parameter(Mandatory=$true)]
[string]$SourceLocation)
return "Hello from $SourceLocation"
}
...
$moduleName = 'Code';
Describe $moduleName {
Context "$Function - Returns a result " {
It "does something useful with just $Function function name" {
$true | Should Be $true
}
}
Context "$Function - Returns with no input " {
It "with no input returns Mandatory value expected" {
Code | Should Throw
}
}
Context "$Function - Returns some output" {
It "with a name returns the standard phrase with that name" {
Code "Venus" | Should Be "Hello from Venus"
}
It "with a name returns something that ends with name" {
Code "Mars" | Should Match ".*Mars"
}
}
} #End Describe
AppVeyorから私の出力は、[+]緑色であり、この結果を示し、[ - ]は赤色であるが私はできる限り最善を尽くしています。私はPowerShellのからのメッセージ応答の特定の種類を克服し、ユニットテストにこれを翻訳するかどうかはわかりませんとそこに緑色の条件を希望としてすべてのヘルプは高く評価され
Describing Code
Context Code - Returns a result
[+] does something useful with just Code function name 16ms
Context Code - Returns with no input
[-] with no input returns Mandatory value expected 49ms
Cannot process command because of one or more missing mandatory parameters: SourceLocation.
at <ScriptBlock>, C:\projects\code\Code.Tests.ps1: line 117
117: Code | Should Throw
Context Code - Returns some output
[+] with a name returns the standard phrase with that name 23ms
[+] with a name returns something that ends with name 11ms
...パー
[ThrowとNot Throwのテストはスクリプトブロックを入力する必要があります](https://github.com/pester/wiki/Should#throw)ので、 '{Code} |投げるべきである ' – TessellatingHeckler
あなたは何を知っていますか...それは動作します!ありがとう@TessellatingHeckler –