Pester Mocking Aduser

Welcome Forums Pester Pester Mocking Aduser

Viewing 1 reply thread
  • Author
    • #68335
      Topics: 3
      Replies: 7
      Points: 0
      Rank: Member

      So I am trying to start using pester more to validate my scripts and I am having a bit of a hard time understanding how to use mock. Here is a quick function I put together and the tests. I am trying to mimic a function that gets an Aduser and throws an error if user is not found.
      #### Function

      ## Test

      Here is the output

      Am I approaching the mock function correctly?

    • #68523
      Topics: 25
      Replies: 43
      Points: 45
      Rank: Member

      Hi James,

      I am also on this journey learning DSC along with Pester. I was trying to learn/understand how to utilize Mocking within my Unit testing. Looking at your cod you have to mock the function and not the cmdlet within it. I also removed your Explicit Parameters within your function because when I ran the test and tried to mock the values out, it still expected the parameters. I believe there is a way to avoid this, but I am unaware at the moment. Anyhow I updated your tests with some Mock data to return. I believe since these are expected to be unit testing, you mock out the expected responses for your function and if that changes in the future so does your tests. When you create Integration testing, then you would actually pass in valid data.

      Not sure if this helps any. Good luck!

Viewing 1 reply thread
  • The topic ‘Pester Mocking Aduser’ is closed to new replies.