我对 Ruby/Rails 的 TDD 和 BDD 有一定的了解,但我最终需要对我的 JavaScript 代码使用某种形式的测试。我使用 MooTools 作为 JS 框架,我非常喜欢用它的代码库很好地组织和模块化我的代码。但是,有时,当我向应用程序添加新功能时,我发现该功能很容易打破以前的工作方式。
在测试 JavaScrtpt 代码时,测试本身是否缺乏用户交互?它真的只是为了测试 JavaScript 中方法和(模拟)类的来龙去脉吗?或者是否有用户体验测试实践,您可以编写单元测试来查看应用程序的用户体验行为是否按应有的方式执行?我知道“行为”是一个广泛的术语,但是无论如何,您是否可以组织您的 JavaScript 测试,以便每当您添加新内容时,您就可以(在某种程度上)放心,您的新代码不会破坏以前的任何内容?对于任何较大的网络应用程序来说,这是如何完成的?
I'm somewhat informed with TDD and BDD with Ruby/Rails, but I will eventually need to use some form of testing with my JavaScript code. I use MooTools as a JS framework and I absolutely love how well I can organize and modularize my code with its codebase. But, sometimes, when I add new features to my application, I find that the functionality can easily break from how it worked before.
When it comes to testing JavaScrtpt code, does the testing itself fall short of user interaction? Is it really only to test the ins and outs of method and (emulated) classes in JavaScript? Or is there a UX testing practice where you can write unit tests to see if your application's UX behaviour is performing how it should be? I'm aware that "behaviour" is a broad term, but is there anyway that you can organize your JavaScript tests so that whenever you add something new then you can rest (somewhat) assured that your new code won't break anything from before? How is this done with any of the larger web apps out there?
发布评论
评论(1)
完全可以,已接受并建议使用单元测试框架,例如 JSSpec 或 Jasmine (还有很多其他的)。
然后,您可以使用 Ghostbuster 或 硒。这些允许您伪造用户事件和交互。
Ghostbuster 还很年轻,所以我们对“实际”用途了解不多,但 Selenium 是一个行业标准(我知道它在 IBM 使用,来源:在 IBM 工作的老师)。
然而,您无法自动测试的是UX。 UX 代表用户体验,这不是您在软件上测试的东西,只能通过真实的用户测试来测试。
It is perfectly fine, accepted and advised to use unit testing frameworks such as JSSpec or Jasmine (there are many others).
Then, you may do UI unit, functional and sometimes even integration testing with tools such as Ghostbuster or Selenium. These allow you to fake user events and interaction.
Ghostbuster is still quite young, so we don't know so much about “actual” uses, but Selenium is an industry standard (I know it is used at IBM, source: teacher working at IBM).
However, what you can't automatically test is UX. UX stands for User eXperience, and that's not something you test on software, only with real user testing.