Cucumber可以提示输入吗?
运行 Cucumber 功能时是否可以提示用户输入?
例如,我要在 Rails 应用程序中添加用户身份验证功能,但由于身份验证将通过外部服务进行,因此我无法出于测试目的设置虚拟帐户。
我最初的计划是简单地提示用户输入用户名和密码以在测试期间使用,但 Cucumber 似乎不喜欢在步骤定义中这样做。
我知道这会使自动化测试变得更加困难,但我不确定如何包含此身份验证功能。有没有办法获取用户输入,或者是否有另一种使用模拟的方法可以更好地工作?或者,是否有方法可以传递任意参数以在运行时在步骤定义中使用?
Is it possible to prompt the user for input while running a Cucumber feature?
For example, I'm adding a feature for user authentication in a Rails app, but since authentication will be happening through an external service, I can't set up a dummy account for the purposes of the test.
My initial plan was to simply prompt the user for a username and password to use during the test, but Cucumber doesn't seem to like doing that in a step definition.
I know that this would make automated testing more difficult, but I'm not sure how else to include this authentication feature. Is there a way to get user input, or is there another approach that uses mocks that would work better? Alternatively, are there ways to pass arbitrary arguments to use in the step definitions at runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定是否使用模拟,但似乎如果您需要特定于环境的用户帐户进行测试,您应该使用环境变量:
然后在您的代码中:
编辑:现在我想它,你几乎肯定不会从你的测试中使用真正的 API。
I'm not sure about using mocks but it seems like if you need an environment-specific user account for testing, you should be using environment variables:
Then in your code:
Edit: Now that I think about it, you should almost certainly not be hitting a real API from your tests.
我会考虑使用 VCR gem 记录与外部服务的交互并回放以供后续测试运行:
https ://www.relishapp.com/myronmarston/vcr
I would consider using the VCR gem to record the interaction with the external service and play it back for subsequent test runs:
https://www.relishapp.com/myronmarston/vcr