Node.js 和 Coffeescript——使用 Mocha 和 Zombie 测试应用程序
我正在尝试测试我已经开始使用的 Node.js Web 应用程序 摩卡和僵尸。但有几件事我还是不明白 并想要一些帮助。请注意,我正在使用express
假设我正在测试用户身份验证。显然有两个 部分: 1 - 用户界面 2 - 行为,涉及控制器和模型 所以,我决定将这两个部分分开。对于用户界面,我决定 使用僵尸。以下链接包含我编写的 UI 测试 用户身份验证: https://gist.github.com/7e45d6884ce2d32e933d 基本上,我的用户身份验证表单包含用户名和 密码输入字段和登录按钮。我对四个感兴趣 场景:当至少一个输入字段为空并且两个输入字段都为空时 已由用户提供。 虽然现在四项测试都通过了,但我仍然不相信它们 是正确的测试,或者是否足够或做了正确的事情。 你们(BDD专家)怎么看? 谢谢 何塞
I am trying to test a node.js webapp I have started working on with
Mocha and Zombie. But there are a few things I still don't understand
and would like some help. Please note that I am using express
Suppose I am testing the user authentication. Obviously there are two
parts:
1 - the user interface
2 - the behavior, involving the controllers and the models
So, I've decided to separate both parts. For the UI, I have decided to
use zombie. The following link contains the UI tests I've written for
the user authentication: https://gist.github.com/7e45d6884ce2d32e933d
Basically, my user authentication form contains a username and
password input fields and a Sign In button. I am interested in four
scenarios: when at least one of the input field is empty and when both
have been provided by the user.
Although the four tests pass right now, I am still not convinced they
are the right tests, or whether it's enough or does the right thing.
What do you guys (BDD experts) think?
thanks
José
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的测试似乎是异步的,因此您应该调用为
it
函数的回调提供的done
函数您可能还想检查您的应用程序在身份验证错误时打印的错误消息。
除了检查给出的所有字段之外,如果您的应用提供了该错误消息,您还应该测试有效的身份验证、错误的密码和现有用户名。如果您只允许每隔几分钟尝试多次登录,也请进行测试。
除了
Since your tests seem to be asynchronous, you should be calling the
done
function given to the callback of theit
functionYou might also want to check for the error message your app prints when there is an error authenticating.
Besides checking all the fields are given, you should also test a valid authentication, a wrong password, and existing username if your app provides that error message. And if you went as far as only allowing a number of attempted logins every few minutes, test for that too.