2012-01-31 38 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

相關問題