jquery 团队的 javascript 测试工具 qunit

今天写了点 Javascript 的小东西,想做个测试,google了一下,看到 jquery 团队使用的测试工具 qunit (http://docs.jquery.com/QUnit) 。有一篇中文文章 http://www.cnblogs.com/nuaalfm/archive/2010/02/26/1674235.html 介绍了这个工具,我尝试了一下,文中的示例已经略有陈旧,跟最新的 qunit 有点不兼容,我稍微改动了一下。

代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <link rel="stylesheet" href="http://localhost/static/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/static/qunit.js" ></script>
  <script>
      $(document).ready(function() {
          test("一个基本测试例子", function() {
              ok( true, "测试布尔类型" );
              var value = "hello";
              QUnit.equal("hello", value, "我们期望得到hello" );
          });
          test("a basic test example", function() {
              ok(true, "this test is fine");
              var value = "hello";
              QUnit.equal("hello", value, "We expect value to be hello");
          });

          module("Module A");

          test("first test within module", function() {
              ok(true, "all pass");
          });

          test("second test within module", function() {
              ok(true, "all pass");
          });

          module("Module B");

          test("some other test", function() {
              expect(2);
              QUnit.equal(true, false, "failing test");
              QUnit.equal(true, true, "passing test");
          });

      });
  </script>
</head>
<body>
  <h1 id="qunit-header">Levenshtein Ditstance QUnit</h1>
  此页面需要 qunit 支持
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
</body>
</html>

因为我用 MAC ,自带了一个web server,所以将依赖的 qunit.css 和 qunit.js 放在了http://localhost/static,windows用户可以使用 iis 。另外代码中使用了 JQuery 官网的 jquery-last.js ,所以需要联网。具体的介绍可以看原作者的文章,很容易上手


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ccat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值