2012-01-31 37 views
1

我尝试qUnit第一次,但不能得到任何测试运行。我创建了一个HTML文件,添加了qunit CSS和JavaScript文件的链接,但是当我打电话测试时,什么都没有发生。测试运行状态为“0通过0测试,0失败”。有任何想法吗?这里的源:qUnit为什么不能识别我的测试?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" /> 
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
    test("a basic test example", function() { 
     ok(true, "this test is fine"); 
    }); 
    }); 
</script> 
</head> 
<body> 
<h1 id="qunit-header">QUnit example</h1> 
<h2 id="qunit-banner"></h2> 
<div id="qunit-testrunner-toolbar"></div> 
<h2 id="qunit-userAgent"></h2> 
<ol id="qunit-tests"></ol> 
<div id="qunit-fixture">test markup, will be hidden</div> 
</body> 
</html> 

回答

6

你需要有这样的

<!DOCTYPE html> 
    <html> 
    <head> 
     <title>Test title</title> 
     <link href="../../Content/qunit.css" rel="stylesheet" type="text/css" /> 
     <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script> 
     <script src="../../Scripts/qunit.js" type="text/javascript"></script> 
     <script src="yourtestfile.js" type="text/javascript"></script> 
    </head> 
    <body> 
     <h1 id="qunit-header">Test title</h1> 
     <h2 id="qunit-banner"></h2> 
     <div id="qunit-testrunner-toolbar"> 
     </div> 
     <h2 id="qunit-userAgent"></h2> 
     <ol id="qunit-tests"> 
     </ol> 
     <div id="qunit-fixture"> 
      <div id="container"></div> 
     </div> 
    </body> 
    </html> 

一个html文件,使其中包含你的测试一个单独的js文件。该文件应该看起来像

(function ($) { 

     module("Your module name", { 
      setup: function() { 
       //your setup code goes here 
      }, 
      teardown: function() { 
       //your teardown code goes here 
      } 
     }); 

     test("This is your first test", function() { 
      ok(true, "this test passed");  
     }); 

    })(jQuery); 

并将其包括到您的html页面。

而只是在浏览器中查看html页面。

我警告你,qunit会让人上瘾! :)

+0

看起来qunit文档已过时。谢谢你。 http://qunitjs.com/cookbook/ – Stokedout 2013-08-19 09:30:30

+0

*更正文档是好的,看起来像我没有qunit.js/css的最新版本 – Stokedout 2013-08-19 09:35:26

+0

对于其他人在看这个问题,请记住拼写所有的文件名称正确! – 2014-03-23 17:39:15

相关问题