Should prompt?

34 views
Skip to first unread message

craig buchanan

unread,
Nov 14, 2016, 5:34:02 PM11/14/16
to Pester
Is there a way to test if a script prompts for a value (perhaps multiple prompts)? 

I'm hoping to test if a session variable is empty, if it is, the script should prompt for a value to populate it.

Dave Wyatt

unread,
Nov 14, 2016, 5:50:48 PM11/14/16
to craig buchanan, Pester
Depends on how you're doing the prompts. If you're using PowerShell's APIs (mandatory parameters, PromptForChoice method, etc), then you can run your tests with "powershell.exe -NonInteractive", and test for the exceptions that get thrown if the code tries to prompt under those conditions. 

If you're writing your own prompt code with Read-Host or something like that, the usual Mocking approach should be fine. 

On Nov 14, 2016, at 5:34 PM, craig buchanan <cra...@gmail.com> wrote:

Is there a way to test if a script prompts for a value (perhaps multiple prompts)? 

I'm hoping to test if a session variable is empty, if it is, the script should prompt for a value to populate it.

--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

craig buchanan

unread,
Nov 14, 2016, 8:22:47 PM11/14/16
to Pester, cra...@gmail.com
The later.

Will you please elaborate on the second approach? 

Dave Wyatt

unread,
Nov 14, 2016, 8:23:52 PM11/14/16
to craig buchanan, Pester
Well, you could mock Read-Host and then use Assert-MockCalled to ensure that it was called, for example.  Or you could put all your custom prompt code into a single PowerShell function, and just mock that.

To unsubscribe from this group and stop receiving emails from it, send an email to pester+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages