您使用过哪些JavaScript单元测试和模拟框架? [英] What are some JavaScript Unit Testing and Mocking Frameworks you have used?

查看:112
本文介绍了您使用过哪些JavaScript单元测试和模拟框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要JavaScript框架是 jQuery ,所以我希望我的单元测试和模拟框架与之兼容。我宁愿不必介绍另一个JavaScript框架。

My main JavaScript framework is jQuery so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework.

我目前正在使用 QUnit 和用于模拟的 Jack ,但我很擅长JavaScript的整个单元测试。

I am currently using QUnit for unit testing and Jack for mocking, but I am pretty new to the whole unit testing of JavaScript.

还有其他人有更好的工具建议吗?什么对你有用?

Does anyone else have a better tool to suggest? What has worked for you?

推荐答案

QUnit

jQUnit

用QUnit和jQUnit编写JS测试

QUnit是jQuery JavaScript框架的单元测试框架。测试框架本身使用jQuery库,但是可以为任何JavaScript编写测试,并且不需要代码使用jQuery。 JQUnit是QUnit的修改版本,它添加了更典型的xUnit框架的setup,teardown和assert函数,并将所有内容封装在一个全局变量中。

QUnit is the unit testing framework for the jQuery JavaScript framework. The testing framework itself uses the jQuery library, but the tests can be written for any JavaScript and do not require the code to use jQuery. JQUnit is a modified version of QUnit that adds in the setup, teardown, and assert functions that are more typical of an xUnit framework, and encapsulates everything in one global variable.

testrunner页面的可视化界面很不错,允许您深入查看每个测试方法中的每个断言。编写测试非常简单,您可以直接在testRunner页面上运行测试代码[8]。这允许简单和可见的DOM测试。

The visual interface of the testrunner page is nice, allowing you to drill down and see each assert in every test method. Writing tests is fairly easy, and you can run the test code directly on the testRunner page [8]. This allows for easy and visible DOM testing.

QUnit:MIT或GPL(选择)jQUnit:MIT许可证

QUnit: MIT or GPL (choose) jQUnit: MIT License

优点

- 异步支持

- 适用于DOM测试

- 测试总是按照添加顺序依次运行套件

- 使用firebug在测试页面上调试

- 如果使用JQUnit,语法类似于JUnit,但是如果使用QUnit则很容易学习

缺点

- 自动化很难实现

Pros
- Asynchronous support
- Good for DOM testing
- Tests always run sequentially in the order they are added to a suite
- Debug on test page using firebug
- Syntax is similar to JUnit if using JQUnit, but simple to learn if using QUnit
Cons
- Automation would be difficult to implement

这篇关于您使用过哪些JavaScript单元测试和模拟框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆