Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created February 22, 2020 08:06
Show Gist options
  • Save nohwnd/b5b0155ff300c8e78de2c948157940b7 to your computer and use it in GitHub Desktop.
Save nohwnd/b5b0155ff300c8e78de2c948157940b7 to your computer and use it in GitHub Desktop.
Pass various parameters to Pester
# output
Pester v4.9.0
Executing all tests in 'C:\Users\jajares\Dropbox\pester\parameters.tests.ps1'
Executing script C:\Users\jajares\Dropbox\pester\parameters.tests.ps1
Describing a
[+] b 31ms
[+] c 15ms
Describing g
[+] Path 14ms
Tests completed in 418ms
Tests Passed: 3, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0
param($p)
function Get-User {
@{
Name = "Jakub"
Age = 31
}
}
Describe "a" {
BeforeAll {
$user = Get-User
}
It "b" {
$user.Name | Should -Be $p.Test1.Name
}
It "c" {
$user.Age | Should -Be $p.Test1.Age
}
}
Describe "g" {
It "Path" {
$p.Test2.Path | Should -Exist
}
}
Get-Module Pester | Remove-Module
Import-Module Pester -MaximumVersion 4.99.99
Invoke-Pester -Script @{
Path = "C:\Users\jajares\Dropbox\pester\parameters.tests.ps1"
Parameters = @{
P = @{
Test1 = @{
Name = "Jakub"
Age = 31
}
Test2 = @{
Path = "C:\temp"
}
CommonParameter1 = "abc"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment