Use Multiple Mocks to Test Function?

Welcome Forums Pester Use Multiple Mocks to Test Function?

Viewing 1 reply thread
  • Author
    • #70643
      Topics: 2
      Replies: 0
      Points: 0
      Rank: Member

      I’m a newbie to Pester so please forgive me if this has been answered already. I want to run multiple unit tests on a PowerShell function, providing a range of mocks to exercise the function. Below is the function and test code I’ve written. I’d like to mock Get-WASJob multiple times, providing a separate mock to each unit test.
      How do I do this?

      Pester code to test the above function:

    • #70684
      Topics: 28
      Replies: 140
      Points: 59
      Rank: Member

      Hi John,

      You should create multiple mocks with different parameter filters. This will allow you to have your Get-WasJob mocks to return different objects.

      Here’s an example.

      Once you’ve got the mocks created and “tagged” as verifiable, you can then run

      to assert that each of them was called. Since you’ve set a parameter filter on each of the mocks, you can then trust that if all of the mocks were called then that means each of the parameter sets were used on those mocks.

Viewing 1 reply thread
  • The topic ‘Use Multiple Mocks to Test Function?’ is closed to new replies.