Cucumber可以提示输入吗?

发布于 2024-12-17 14:48:33 字数 281 浏览 2 评论 0原文

运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多像笑话 2024-12-24 14:48:33

我不确定是否使用模拟,但似乎如果您需要特定于环境的用户帐户进行测试,您应该使用环境变量:

$ SOME_USERNAME=foo SOME_PASSWORD=bar rake test:features

然后在您的代码中:

foo = MyAwesomeFooClass.new(ENV["SOME_USERNAME"], ENV["SOME_PASSWORD"])

编辑:现在我想它,你几乎肯定不会从你的测试中使用真正的 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:

$ SOME_USERNAME=foo SOME_PASSWORD=bar rake test:features

Then in your code:

foo = MyAwesomeFooClass.new(ENV["SOME_USERNAME"], ENV["SOME_PASSWORD"])

Edit: Now that I think about it, you should almost certainly not be hitting a real API from your tests.

请爱~陌生人 2024-12-24 14:48:33

我会考虑使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文