2012-01-31 14 views
1

初めてqUnitを試していますが、テストを実行することはできません。 qunit CSSとJavaScriptファイルへのリンクを追加したHTMLファイルを作成しましたが、私がtestを呼び出すと何も起こりません。テスト実行では、0回の0回のテスト、0回の失敗が示されます。何か案は?ここではソースがあります:あなたはこのようなhtmlファイルを持っている必要があり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> 

は、あなたのテストが含まれている別々の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

+0

*最新のqunit.js/css – Stokedout

+0

の最新版を持っていなかったようです。ファイル名は正しく! –

関連する問題