PowerShell Pester - Code Coverage
$here = Split-Path -Parent $MyInvocation.MyCommand.Path$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe "Test" {
Context "Should be test"{
It "Add 1 and 2 is equal to 3" {
add 1 2 | Should Be 3
}
It "Add -1 and 2 is not equal to 0" {
add -1 2 | Should not Be 0
}
It "Test Switch option"{
switchtest -switch | Should be "Switch is on"
}
}
Context "Should BeExactly test"{
It "HostName" {
hostname | Should beexactly "yli-ise"
}
}
Context "Should BeGreaterThan test"{
It "PsVersion is above 3" {
$PSVersionTable.PSVersion.Major | Should beGreaterThan 3
}
}
Context "Should beOfType test"{
It "Get-ADUser type"{
Get-aduser yli | Should beoftype Microsoft.ActiveDirectory.Management.ADUser
}
}
Context "Should Exist test"{
It "C:\temp exist"{
"c:\temp" | should exist
}
}
Context "Should match test"{
It "Find Email"{
"jksjsjsjssdjs abc.xyz@yahoo.com hsosofs" | should match "+(?:\.+)*@(?:(?:*)?\.)+(?:*)?"
}
}
Context "Should Throw test" {
It "Get a non-exist Process"{
{Get-Process -Name "!@#$%&" -ErrorAction Stop} | Should Throw
}
}
Context "Should BeNullorEmpty test"{
It "Get something from test folder"{
get-childitem C:\temp | should not benullorempty
}
}
}
页:
[1]