如何使用pester測驗框架撰寫一個小的測驗函式
function SaveStudent($Student){
Write-Host "save student email for $($Student.Email)
return $Student
}
uj5u.com熱心網友回復:
我們已經使用 pester 框架撰寫了一個示例測驗函式并在本地環境中進行了測驗。下面是示例 Get-Something 函式,這里是函式模塊:
function Get-Something {
[CmdletBinding()]
param (
[Parameter()]
[string]
$ThingToGet
)
if ($PSBoundParameters.ContainsKey('ThingToGet')) {
Write-Output "I got $ThingToGet!"
}
else {
Write-Output "I got something!"
}
}
以下是功能模塊測驗用例
Describe "Get-Something" {
Context "when parameter ThingToGet is not used" {
It "should return 'I got something!'" {
Get-Something | Should -Be 'I got something!'
}
}
Context "when parameter ThingToGet is used" {
It "should return 'I got ' follow by a string" {
$thing = 'a dog'
Get-Something -ThingToGet $thing | Should -Be "I got $thing!"
}
}
}
有關更多資訊,您可以參考此 博客或糾纏檔案快速啟動糾纏測驗框架作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/334380.html
標籤:天蓝色 电源外壳 单元测试 azure-devops 纠缠
上一篇:Deno在單元測驗中模擬命名匯入
