【问题标题】:QUnit can't recognize more than one testQUnit 不能识别多个测试
【发布时间】:2012-06-13 19:17:55
【问题描述】:

我在使用 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>

【问题讨论】:

    标签: javascript unit-testing testing qunit


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      安静得令人沮丧。

      【讨论】:

      • 谢谢,谢谢,谢谢你的清晰,准确的回答。这已经杀死了我 20 分钟!
      • 很沮丧,但是一旦我开始玩数字 ?testNumber=1,2,3... 就变得有趣了...有趣的是,它只执行我通过的任何数字的特定测试用例 :) 非常感谢答案。
      【解决方案3】:

      这是sample page that will run more then one test

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-04
        • 2015-12-20
        • 2015-08-05
        • 2012-10-13
        相关资源
        最近更新 更多