New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock CommandNotFoundException: Could not find Command Invoke-Sqlcmd #2399
Comments
@ertanergunswapfiets moved your issue here, from the closed issue. Can you plese post how you define the mock? And are you trying to mock in some module scope? |
First of all the script I am trying to test is running as a Runbook in Azure so it is not a function. I thought it was the problem and I put it it in a function to test it. here is the script file i am trying to test now script.ps1:
Originally the runbook funtion didnt exist so I just surrounded the actual script with a funtion. Here is the test file script.Tests.ps1:
I also tried Mock command with giving ModuleName CommandName without MockWith but i couldn't succeed. This is the output of test:
I have 2 functions/commands to mock, one is Get-AutomationPSCredential and other is Invoke-Sqlcmd. When I comment out one I confirm that the other also fails so issue is with mocking both. |
The original commands has to be available in your session for Pester to be able mock them, as it needs to see which parameters to copy etc. Usually you'd import the necessary modules/dependencies before invoking the tests. If you don't have access to the modules containing |
@ertanergunswapfiets If you need stub function for Or, create your own using the steps in the README. |
And here is where I call it
Originally posted by @ertanergunswapfiets in #1592 (comment)
The text was updated successfully, but these errors were encountered: