Почему qUnit не распознает мой тест? - PullRequest
1 голос
/ 31 января 2012

Я пробую qUnit впервые, но не могу запустить ни одного теста.Я создал файл HTML, добавил ссылки на файлы CSS и JavaScript qunit, но при вызове test ничего не происходит.Тестовый прогон гласит «0 тестов из 0 пройденных, 0 неудачных».Есть идеи?Вот источник:

<!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>

1 Ответ

7 голосов
/ 31 января 2012

Вам нужен HTML-файл, подобный этому

 <!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", {
            beforeEach: function () {
                 //your setup code goes here
             },
            afterEach: function () {
                //your teardown code goes here
            }
        });

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

    })(jQuery);

И включите это на свою html-страницу.

И просто просмотрите HTML-страницу в браузере.

Я предупреждаю вас, Quitit вызывает привыкание! :)

...