Tests/Publish-PsmModule.Tests.ps1
$moduleRoot = Resolve-Path "$PSScriptRoot\.." $moduleName = Split-Path $moduleRoot -Leaf Describe "How to mock a function" { context 'Where get-stuff return nothing' { Mock get-stuff { } it "should return 1" { get-otherStuff | Should -be 1 } } context 'Where get-stuff return 5' { Mock get-stuff -MockWith { 5 } it "should return 6" { get-otherStuff | Should -be 6 } } } $testCases = @( @{ a = 0; b = 1; ExpectedResult = 1 } @{ a = 1; b = 0; ExpectedResult = 1 } @{ a = 1; b = 1; ExpectedResult = 0 } @{ a = 0; b = 0; ExpectedResult = 0 } ) Describe "A test with paramterized test cases" { It "Publish-PsmModule <a> <b> should be <expectedresult>" -TestCases $testCases { param ($a, $b, $ExpectedResult) Publish-PsmModule $a $b | Should -Be $ExpectedResult } } Describe "BeforAll & AfterAll features" { Write-Host -For DarkRed "Before Context" BeforeAll { Write-Host -for DarkGreen "In Describe BeforeAll" } AfterAll { Write-Host -for DarkGreen "In Describe AfterAll" } Context "subsection" { Write-Host -for DarkRed "Before BeforeAll" BeforeAll { write-host -for Blue "In Context BeforeAll" } Write-Host -for DarkRed "After BeforeAll" Write-Host -for DarkRed "Before AfterAll" AfterAll { Write-Host -for Blue "In Context AfterAll" } Write-Host -for DarkRed "After AfterAll" BeforeEach { Write-Host -for Blue "In BeforeEach" } AfterEach { Write-Host -for Blue "In AfterEach" } Write-Host -for DarkRed "Before It" It "should not be a surprise" { 1 | should -Be 1 } Write-Host -for DarkRed "After It" } } |