单元测试模块化 javascript
我目前正在派生一个 javascript 框架模式,作为我即将开发的大型应用程序的客户端开发架构。
我希望采用模块观察者模式,其中我开发的每个控件都有自己的 javascript 文件,不了解其他控件。
从为我的应用程序设计这个框架开始,我希望集成我的模块的测试机制 - javascript 的单元测试机制。我不知道任何这样的框架或我如何建立这样的框架。有什么建议吗?
作为此类测试的一部分,我还需要模拟 http 请求。
我将在开发中使用的库是 jquery。
I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.
I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.
From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?
As part of such testing, I will also need to mock up http requests.
The library I will be using in development is jquery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JQuery 团队拥有 QUnit。
至于抽象出 AJAX,您应该适当地包装它或者只测试数据操作方法。
The JQuery team has QUnit.
As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.
Jasmine 可能就是您正在寻找的。它具有内置的模型支持,并且不依赖于任何其他框架。
他们还有一个单独的 模块 用于伪造 AJAX 响应。
设置很简单。只需下载独立版本,编写一些测试套件,然后在浏览器中查看 SpecRunner.html 即可。
Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.
They also have a separate module for faking AJAX responses.
The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
考虑使用 JsTestDriver 运行 JS 测试。它提供的主要好处 - 它可以在持续集成环境中运行测试,这对于单元测试实践至关重要。
一些附加功能:
您可以在另一个 线程。
Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.
Some additional features:
List of mocking libraries you can find in another thread.
BoilerplateJS
是大规模 JavaScript 产品开发的参考架构。您可以在 tests 文件夹下找到使用 qunit、sinon 和 testr 编写的测试。< /a>
BoilerplateJS
is a reference architecture for large scale JavaScript product development. You can find the tests which are written using qunit, sinon and testr included under the tests folder.