你使用过哪些 JavaScript 单元测试和模拟框架? [英] What are some JavaScript unit testing and mocking frameworks you have used?

查看:19
本文介绍了你使用过哪些 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.

有没有更好的工具可以推荐?什么对你有用?

Is there a better tool to suggest? What has worked for you?

推荐答案

QUnit
jqUnit
使用 QUnit 和 jqUnit 编写 JavaScript 测试

QUnit 是 jQuery JavaScript 框架的单元测试框架.测试框架本身使用 jQuery 库,但测试可以为任何 JavaScript 编写,不需要代码使用 jQuery.

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 是 QUnit 的修改版本,它添加了更典型的 xUnit 框架的 setup、teardown 和 assert 函数,并将所有内容封装在一个全局变量中.

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,则易于学习

缺点

  • 自动化将难以实施

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

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