javascript QUnit 单元测试
<!doctype html>
<html>
<head lang="zh-CN" dir="ltr">
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body> <!--qunit start-->
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<!--qunit end--> <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script> <script type="text/javascript" src="demo.js"></script>
</body>
</html>
test( "ok test", function() {
ok( true, "true succeeds" );
ok( "non-empty", "non-empty string succeeds" );
ok( false, "false fails" );
ok( 0, "0 fails" );
ok( NaN, "NaN fails" );
ok( "", "empty string fails" );
ok( null, "null fails" );
ok( undefined, "undefined fails" );
});
test( "strictEqual test", function() {
strictEqual( 1, 1, "1 and 1 are the same value and type" );
});
test( "a test", function() {
notStrictEqual( 1, "1", "String '1' and number 1 don't have the same value" );
});
test( "throws", function() {
function CustomError( message ) {
this.message = message;
}
CustomError.prototype.toString = function() {
return this.message;
};
throws(
function() {
throw "error"
},
"throws with just a message, no expected"
);
throws(
function() {
throw new CustomError();
},
CustomError,
"raised error is an instance of CustomError"
);
throws(
function() {
throw new CustomError("some error description");
},
/description/,
"raised error message contains 'description'"
);
});
asyncTest( "asynchronous test: one second later!", function() {
expect( 1 );
setTimeout(function() {
ok( true, "Passed and ready to resume!" );
start();
}, 1000);
});
test( "a test", function() {
stop();
asyncOp();
setTimeout(function() {
equals( asyncOp.result, "someExpectedValue" );
start();
}, 150 );
});
test( "a test", function() {
stop();
asyncOp();
setTimeout(function() {
equals( asyncOp.result, "someExpectedValue" );
start();
}, 150 );
});
QUnit.done(function( details ) {
console.log( "Total: ", details.total, " Failed: ", details.failed, " Passed: ", details.passed, " Runtime: ", details.runtime );
});
asyncTest( "asynchronous test: one second later!", function() {
expect( 1 );
setTimeout(function() {
ok( true, "Passed and ready to resume!" );
start();
}, 1000);
});
asyncTest( "asynchronous test: video ready to play", 1, function() {
var $video = $( "video" );
$video.on( "canplaythrough", function() {
ok( true, "video has loaded and is ready to play" );
start();
});
});
test( "a test", function() {
expect( 2 );
function calc( x, operation ) {
return operation( x );
}
var result = calc( 2, function( x ) {
ok( true, "calc() calls operation function" );
return x * x;
});
equal( result, 4, "2 square equals 4" );
});
test( "a test", 2, function() {
function calc( x, operation ) {
return operation( x );
}
var result = calc( 2, function( x ) {
ok( true, "calc() calls operation function" );
return x * x;
});
equal( result, 4, "2 square equals 4" );
});
module( "group a" );
test( "a basic test example", function() {
ok( true, "this test is fine" );
});
test( "a basic test example 2", function() {
ok( true, "this test is fine" );
});
module( "group b" );
test( "a basic test example 3", function() {
ok( true, "this test is fine" );
});
test( "a basic test example 4", function() {
ok( true, "this test is fine" );
});
javascript QUnit 单元测试的更多相关文章
- 对 JavaScript 进行单元测试的工具
简介 单元测试关注的是验证一个模块或一段代码的执行效果是否和设计或预期一样.有些开发人员认为,编写测试用例浪费时间而宁愿去编写新的模块.然而,在处理大型应用程序时,单元测试实际上会节省时间:它能帮助您 ...
- javascript之QUnit单元测试
一.javascript也需要单元测试吗? 这里我并不知道你有没有开发过大型的javascript项目,至今我开发过三个大型的js项目,分为是<课程节点树管理>.<在线制作试卷> ...
- 测试工具使用-Qunit单元测试使用过程
031302620 应课程要求写一篇单元测试工具的博客,但是暂时没用到java,所以不想使用junit(对各种类都不熟悉的也不好谈什么测试),原计划是要用phpunit,但是安装经历了三个小时,查阅各 ...
- JavaScript 自定义单元测试
<!doctype html> <html> <head> <meta charset="utf-8"> <script> ...
- javascript单元测试框架mochajs详解
关于单元测试的想法 对于一些比较重要的项目,每次更新代码之后总是要自己测好久,担心一旦上线出了问题影响的服务太多,此时就希望能有一个比较规范的测试流程.在github上看到牛逼的javascript开 ...
- javascript单元测试(转)
1. 什么是单元测试 在计算机编程中,单元测试(又称为模块测试)是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工作.程序单元是应用的最小可测试部件.在过程化编程中,一个单元就是单 ...
- 单元测试(qunit)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- (译)学习如何构建自动化、跨浏览器的JavaScript单元测试
作者:Philip Walton 译者:Yeaseon 原文链接:点此查看 译文仅供个人学习,不用于任何形式商业目的,转载请注明原作者.文章来源.翻译作者及链接,版权归原文作者所有. ___ 我们都知 ...
- [转]javascript单元测试
1. 什么是单元测试 在计算机编程中,单元测试(又称为模块测试)是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工作.程序单元是应用的最小可测试部件.在过程化编程中,一个单元就是单 ...
随机推荐
- IOC框架的认识
转:http://blog.csdn.net/wanghao72214/article/details/3969594 1 IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实 ...
- linux设备驱动第五篇:驱动中的并发与竟态
综述 在上一篇介绍了linux驱动的调试方法,这一篇介绍一下在驱动编程中会遇到的并发和竟态以及如何处理并发和竞争. 首先什么是并发与竟态呢?并发(concurrency)指的是多个执行单元同时.并行被 ...
- LAMP环境的搭建
[一些前言废话]一名web开发尤其是后端不懂LAMP环境的搭建,那就摊上事了,有些人说他一直用win下的wampServer这种傻瓜式环境搭建,用的挺好的,也有人说他用云服务器,搭配“一键搭建LAMP ...
- 【BZOJ】【1406】【AHOI2007】密码箱
数论 Orz iwtwiioi 果然数论很捉鸡>_>完全不知道怎么下手 $$x^2 \equiv 1 \pmod n \rightarrow (x+1)*(x-1)=k*n $$ 所以,我 ...
- windows phone中ListBox的简单使用
学习windows phone数据绑定的一点点心得,在wp系统的APP中经常遇到这样风格的软件,那它们到底怎样实现的呢?我就大致去做了一下,比较粗虐,但基本的都已经有了,实现后的结果为: 哇,这个图截 ...
- Nginx使用webbench进行压力测试(转载)
在运维工作中,压力测试是一项非常重要的工作.比如在一个网站上线之前,能承受多大访问量.在大访问量情况下性能怎样,这些数据指标好坏将会直接影响用户体验. 但是,在压力测试中存在一个共性,那就是压力测试的 ...
- IT架构之IT架构模型——思维导图
参考: [日] 野村综合研究所系统咨询事业本部. 图解CIO工作指南. 周自恒译 人民邮电出版社,2014
- 正确使用HTML title属性
如果你想对使用手机,平板电脑和辅助技术的用户隐藏某些内容,而只对键盘用户显示,那么请使用title属性. 细节 HTML的title属性本身有问题.之所以有问题是因为它在一些重要的方面表现的不够好,尽 ...
- POC
大概就是原型验证的意思 验证概念 编辑 概念验证(Proof of concept,简称POC)是对某些想法的一个不完整的实现,以证明其可行性,示范其原理,其目的是为了验证一些概念或理论.在计算机安全 ...
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...