自动化单元测试用JavaScript [英] Automated Unit Testing with JavaScript

查看:123
本文介绍了自动化单元测试用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想结合一些JavaScript的单元测试到我的自动的构建过程。目前JSUnit的使用JUnit运作良好,但它似乎是放弃的,缺乏对AJAX,调试和超时良好的支持。

I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently JSUnit works well with JUnit, but it seems to be abandonware and lacks good support for AJAX, debugging, and timeouts.

有没有人有任何运气自动化(与ANT)单元测试库,如YUI测试,jQuery的QUnit或jQUnit(的 HTTP://$c$c.google.com/p/jqunit/

Has anyone had any luck automating (with ANT) a unit testing library such as YUI test, JQuery's QUnit, or jQUnit (http://code.google.com/p/jqunit/)?

请注意:我使用内置AJAX库的自定义,因此与Dojo的DOH的问题是,它需要你用自己的AJAX功能调用和事件处理程序与任何AJAX单元测试工作。

Note: I use a custom built AJAX library, so the problem with Dojo's DOH is that it requires you to use their own AJAX function calls and event handlers to work with any AJAX unit testing.

推荐答案

有很多JavaScript的单元测试框架在那里(JSUnit的,Scriptaculous的,...),但JSUnit的是唯一一个我知道可以用自动使用建立。

There are many javascript unit test framework out there (jsUnit, scriptaculous, ...) but jsUnit is the only one I know that may be used with an automated build.

如果你正在做的真单元测试你不应该需要AJAX支持。例如,如果您使用的是RPC Ajax框架,如DWR,你可以随便写一个模拟功能:

If you are doing 'true' unit test you should not need AJAX support. For example, if you are using an RPC ajax framework such as DWR, you can easily write a mock function :


   function mockFunction(someArg, callback) {
      var result = ...; // some treatments   
      setTimeout(
function() { callback(result); }, 300 // some fake latency
); }

是的,你JSUnit的处理超时:<一href=\"http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html\">Simulating时间JSUnit的测试

这篇关于自动化单元测试用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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