[英]unit testing modular javascript
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. 我目前正在推出一个javascript框架模式作为客户端开发的架构,用于即将开发的大型应用程序。
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. 我希望使用模块观察器模式,其中我开发的每个控件都有自己的javascript文件,没有其他控件的知识。
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. 从为我的应用程序设计这个框架,我希望集成我的模块的测试机制 - 一个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. 作为此类测试的一部分,我还需要模拟http请求。
The library I will be using in development is jquery. 我将在开发中使用的库是jquery。
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. 他们还有一个单独的模块用于伪造AJAX响应。
The setup is simple. 设置很简单。 Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
只需下载独立版本,编写一些测试套件,然后在浏览器中查看SpecRunner.html即可。
Consider using JsTestDriver to run your JS tests. 考虑使用JsTestDriver来运行JS测试。 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 is a reference architecture for large scale JavaScript product development. BoilerplateJS是大规模JavaScript产品开发的参考架构。 You can find the tests which are written using qunit, sinon and testr included under the tests folder.
您可以在tests文件夹下找到使用qunit,sinon和testr编写的测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.