about_Mocking.help - TOPIC Mocking SYNOPSIS Pester provides a set of Mocking functions making it easy to fake dependencies and also to verify behavior

about_Mocking.help - TOPIC Mocking SYNOPSIS Pester provides...

This preview shows page 1 - 2 out of 4 pages.

TOPIC Mocking SYNOPSIS Pester provides a set of Mocking functions making it easy to fake dependencies and also to verify behavior. Using these mocking functions can allow you to "shim" a data layer or mock other complex functions that already have their own tests. DESCRIPTION With the set of Mocking functions that Pester exposes, one can: - Mock the behavior of ANY powershell command. - Verify that specific commands were (or were not) called. - Verify the number of times a command was called with a set of specified parameters. MOCKING FUNCTIONS See Get-Help for any of the below functions for more detailed information. Mock Mocks the behavior of an existing command with an alternate implementation. Assert-VerifiableMocks Checks if any Verifiable Mock has not been invoked. If so, this will throw an exception. Assert-MockCalled Checks if a Mocked command has been called a certain number of times and throws an exception if it has not. EXAMPLE function Build ($version) { Write-Host "a build was run for version: $version" } function BuildIfChanged { $thisVersion = Get-Version $nextVersion = Get-NextVersion if ($thisVersion -ne $nextVersion) { Build $nextVersion } return $nextVersion } $here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") . "$here\$sut" Describe "BuildIfChanged" {
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 4 pages?

  • Winter '15

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes