QUnit无法识别多个测试

时间:2012-06-10 17:26:54

标签: javascript unit-testing testing qunit

我遇到了QUNIT的问题,无论我做什么,测试套件只能识别一个测试或模块,即使我在javascript中有多个。任何帮助将不胜感激!

    <script>
          $(document).ready(function(){
            QUnit.log = function(result, message)
            {
                if (window.console && window.console.log)
                {
                   window.console.log(result +' :: '+ message);
                }   
            }
            module("Basic Unit Test");
            test("Sample test", function()
            {
                expect(1);
                equal(divide(4,2),2, 'Expected 2 as the result, result was ' + divide(4,2));
            });
                        test("Test two", function() {
                        expect(1);
                        equal(divide(8,2),2,'Expected 4 as the result, result was ' + divide(8,2));
                        });

            function divide(a,b){
                return a / b;
            }
          });

    </script>

3 个答案:

答案 0 :(得分:72)

你可能在Url中有QUnit-Url-Parameters,它限制了对这些过滤器参数中指定的模块/测试的测试(在http://docs.jquery.com/Qunit上看到“URL参数”)。从干净的URL开始,然后执行所有测试。

例如。您的网址包含blah.html?testNumber=1。这意味着只运行一个测试。删除?testNumber=1

答案 1 :(得分:28)

在您进行设置之前,您点击了“重新运行”。这悄悄地在你的网址上添加了一个“?testNumber = 1”,排除了所有其他测试的运行。

令人沮丧的是多么安静。

答案 2 :(得分:3)

这是sample page that will run more then one test

它包含您放在这里的两个测试。