<!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 单元测试的更多相关文章

  1. 对 JavaScript 进行单元测试的工具

    简介 单元测试关注的是验证一个模块或一段代码的执行效果是否和设计或预期一样.有些开发人员认为,编写测试用例浪费时间而宁愿去编写新的模块.然而,在处理大型应用程序时,单元测试实际上会节省时间:它能帮助您 ...

  2. javascript之QUnit单元测试

    一.javascript也需要单元测试吗? 这里我并不知道你有没有开发过大型的javascript项目,至今我开发过三个大型的js项目,分为是<课程节点树管理>.<在线制作试卷> ...

  3. 测试工具使用-Qunit单元测试使用过程

    031302620 应课程要求写一篇单元测试工具的博客,但是暂时没用到java,所以不想使用junit(对各种类都不熟悉的也不好谈什么测试),原计划是要用phpunit,但是安装经历了三个小时,查阅各 ...

  4. JavaScript 自定义单元测试

    <!doctype html> <html> <head> <meta charset="utf-8"> <script> ...

  5. javascript单元测试框架mochajs详解

    关于单元测试的想法 对于一些比较重要的项目,每次更新代码之后总是要自己测好久,担心一旦上线出了问题影响的服务太多,此时就希望能有一个比较规范的测试流程.在github上看到牛逼的javascript开 ...

  6. javascript单元测试(转)

    1.      什么是单元测试 在计算机编程中,单元测试(又称为模块测试)是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工作.程序单元是应用的最小可测试部件.在过程化编程中,一个单元就是单 ...

  7. 单元测试(qunit)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  8. (译)学习如何构建自动化、跨浏览器的JavaScript单元测试

    作者:Philip Walton 译者:Yeaseon 原文链接:点此查看 译文仅供个人学习,不用于任何形式商业目的,转载请注明原作者.文章来源.翻译作者及链接,版权归原文作者所有. ___ 我们都知 ...

  9. [转]javascript单元测试

    1.      什么是单元测试 在计算机编程中,单元测试(又称为模块测试)是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工作.程序单元是应用的最小可测试部件.在过程化编程中,一个单元就是单 ...

随机推荐

  1. 向Array中添加快速排序

    快速排序思路 1) 假设第一个元素为基准元素 2) 把所有比基准元素小的记录放置在前一部分,把所有比基准元素大的记录放置在后一部分,并把基准元素放在这两部分的中间(i=j的位置) 快速排序实现 Fun ...

  2. 向Array中添加插入排序

    插入排序思路 从第二个元素开始和它前面的元素进行比较,如果比前面的元素小,那么前面的元素向后移动,否则就将此元素插入到相应的位置. 插入排序实现 Function.prototype.method = ...

  3. 【Merge Two Sorted Lists】cpp

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  4. 查看python selenium的api

    打开命令行工具,doc中输入: python -m pydoc -p 然后在浏览器中访问http://localhost:4567/,此时应该可以看到python中所有的Modules 按ctrl+f ...

  5. EditPlus配置[C++] [Python] [Java] 编译运行环境

    以前一直用Codeblocks写C++,eclipse写Java,再在eclipse里面集成PyDev写Python,首先无法忍受代码自动补全功能(这个功能也许你万分喜欢),也无法忍受如此重量级的ID ...

  6. 【BZOJ】【2301】problem b

    莫比乌斯反演/容斥原理 Orz PoPoQQQ PoPoQQQ莫比乌斯函数讲义第一题. for(i=1;i<=n;i=last+1){ last=min(n/(n/i),m/(m/i)); …… ...

  7. [转载]115个Java面试题和答案

    不知道大家有没有这样的体会,就是找工作的时候不得不准备大量面试题,而工作的时间长了面试题里的精髓却忘的差不多了... 转载几篇Java面试的bolg,温故而知新,最重要的是常来看看. 1. http: ...

  8. ios中webservice报文的拼接

    1.报文头需要密码验证的 - (void)sendAsynWebServiceRequest:(NSString *)nameSpace method:(NSString *)method reque ...

  9. 基于jQuery很牛X的批量上传插件

    上传功能应该是每个网站必备的工具之一,因此出现了出现了很多各式各样的上传插件! 本文基于个人经验和使用从插件的:交互体验,易用性,文档,美观度出发,为大家推荐三款很NX的批量上传插件! 下面三款插件的 ...

  10. 10个jQuery插件分享

    原文:http://www.shejidaren.com/10-jquery-plugins.html blur.js blur.js是一个很有意思的插件,它能实现像WIN7 AERO效果的JS插件, ...