码迷,mamicode.com
首页 > Web开发 > 详细

JS单元测试框架:QUnit

时间:2015-01-12 20:44:06      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

QUnit:jQuery的单元测试框架,但不仅限于jQuery(从这个工具不需要引用jquery.js可以看出)

index.html

<!--
官网
http://qunitjs.com/
-->
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>QUnit Example</title>
  <link rel="stylesheet" href="qunit-1.16.0.css">
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
  
  <script src="qunit-1.16.0.js"></script>  <!--测试框架-->
  <script src="tests.js"></script>         <!--单元测试模块-->
  <script src="api.js"></script>           <!--被测模块-->

</body>
</html>

api.js

function sum(a, b)
{
    return a + b;
}

 tests.js

QUnit.module( "OnRead", {
    //初始化
    beforeEach: function() {
        console.log("setup");
    },
  
    //清理
    afterEach: function()
    {
        console.log("clean");
    }
});

//测试用例
QUnit.test( "sum", function( assert ) {
    console.log("sum");
    assert.ok( 1 == "1", "Passed!" );
});

直接执行index.html

JS单元测试框架:QUnit

标签:

原文地址:http://www.cnblogs.com/code-style/p/4219531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!