FireUnit:基于Firebug的JavaScript单元测试扩展
2008-12-26 16:18
537 查看
John Resig最近在他的博客中发表文章John Resig - FireUnit: JavaScript Unit Testing Extension.发布了他与Jan Odvarko合作开发的一款基于Firebug的扩展FireUnit。(Firebug真是越来越强大了……)
简单说来,FireUnit给Firebug增加了一个标签面板,并提供了一些简单的JavaScript API来记录和查看测试。
举例来说:
// Simple true-like/false-like testing
fireunit.ok( true, "I'm going to pass!" );
fireunit.ok( false, "I'm going to fail!" );
// Compare two strings - shows a diff of the
// results if they're different
fireunit.compare(
"The lazy fox jumped over the log.",
"The lazy brown fox jumped the log.",
"Are these two strings the same?"
);
// Compare a string using a regular expression
fireunit.reCompare(
/The .* fox jumped the log./,
"The lazy brown fox jumped the log.",
"Compare a string using a RegExp."
);
// Display the total results
fireunit.testDone();
就可以在Firebug中的Test标签面板中看到下图:
FireUnit还可以模拟触发原生浏览器事件:
// You can also simulate browser events
var input = document.getElementsByTagName("input")[0];
fireunit.mouseDown( input );
fireunit.click( input );
fireunit.focus( input );
fireunit.key( input, "a" );
此外,可以批量测试文件(每个文件都含有一些独立测试)
// Or run multiple pages of tests:
fireunit.runTests("test2.html", "test3.html");
// Place at the end of every test file in order to continue
fireunit.testDone();
推荐把测试代码包含在下面的if语句内
if ( typeof fireunit === "object" ) {
//Your code for test
}
如果感兴趣,可以访问Fireunit.org下载并测试(这个网站内就包含了测试代码,安装后即可看到第一张图的内容)
可以在Github上获取源码,得用git而不是svn
Jan也写了一篇文章,可以看看。
简单说来,FireUnit给Firebug增加了一个标签面板,并提供了一些简单的JavaScript API来记录和查看测试。
举例来说:
// Simple true-like/false-like testing
fireunit.ok( true, "I'm going to pass!" );
fireunit.ok( false, "I'm going to fail!" );
// Compare two strings - shows a diff of the
// results if they're different
fireunit.compare(
"The lazy fox jumped over the log.",
"The lazy brown fox jumped the log.",
"Are these two strings the same?"
);
// Compare a string using a regular expression
fireunit.reCompare(
/The .* fox jumped the log./,
"The lazy brown fox jumped the log.",
"Compare a string using a RegExp."
);
// Display the total results
fireunit.testDone();
就可以在Firebug中的Test标签面板中看到下图:
FireUnit还可以模拟触发原生浏览器事件:
// You can also simulate browser events
var input = document.getElementsByTagName("input")[0];
fireunit.mouseDown( input );
fireunit.click( input );
fireunit.focus( input );
fireunit.key( input, "a" );
此外,可以批量测试文件(每个文件都含有一些独立测试)
// Or run multiple pages of tests:
fireunit.runTests("test2.html", "test3.html");
// Place at the end of every test file in order to continue
fireunit.testDone();
推荐把测试代码包含在下面的if语句内
if ( typeof fireunit === "object" ) {
//Your code for test
}
如果感兴趣,可以访问Fireunit.org下载并测试(这个网站内就包含了测试代码,安装后即可看到第一张图的内容)
可以在Github上获取源码,得用git而不是svn
Jan也写了一篇文章,可以看看。
相关文章推荐
- 基于原生JavaScript进行扩展模拟用户长按事件(webapp)
- Javascript单元测试框架Jasmine的扩展封装
- javaScript的单元测试框架Unit.js介绍
- JavaScript基于扩展String实现替换字符串中index处字符的方法
- 发布一个基于javascript的日期扩展
- javascript 单元测试 (Jsunit应用) 转
- javascript QUnit 单元测试
- 基于firebug的firefox扩展 css usage
- Macaca+HTMLTestRunner测试报告模式修改,基于python unittest 测试框架扩展
- 基于unittest测试框架的扩展
- javaScript的单元测试框架Unit.js介绍
- Appium基于python unittest自动化测试并生成html测试报告
- 基于JavaScript创建动态Dom
- 轻松学习JavaScript十二:JavaScript基于面向对象之创建对象(一)
- 用Firebug调试JavaScript
- 基于JavaScript 声明全局变量的三种方式详解
- JavaScript 调用WebService 基于Soap 通讯
- Linux 安装基于(PHP5.5)memcache扩展
- 轻松学习JavaScript十二:JavaScript基于面向对象之创建对象(二)
- 基于javascript的asp数据库操作类,含分页、字符串截取、用户登陆验证[原创]