Should prompt?

已查看 34 次
跳至第一个未读帖子

craig buchanan

未读,
2016年11月14日 17:34:022016/11/14
收件人 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

未读,
2016年11月14日 17:50:482016/11/14
收件人 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

未读,
2016年11月14日 20:22:472016/11/14
收件人 Pester、cra...@gmail.com
The later.

Will you please elaborate on the second approach? 

Dave Wyatt

未读,
2016年11月14日 20:23:522016/11/14
收件人 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.
回复全部
回复作者
转发
0 个新帖子