我已经编写了QUnit测试,并使用Chutzpah Test Adapter for Test Explorer在Visual Studio 2012中运行它们。当我运行代码覆盖时,需要某些外部依赖性的测试(例如jQuery或Kendo)会失败,但是在没有代码覆盖率的情况下运行时会失败。
为我重现问题的示例测试文件:
/// <reference path="qunit-2.5.0.js" />
/// <reference path="../Scripts/jquery-2.1.3.js" />
/// <reference path="../Components/componentEnvironment/componentEnvironment.js" />
module("repro.tests");
test("buildUrl - one part returns part", function () {
var ce = new ComponentEnvironment();
var output = ce.buildUrl(["http://localhost"]);
deepEqual(output, "http://localhost");
});
test("jQuery loaded", function () {
var fixture = $("#qunit-fixture");
fixture.append("<div id='grandparent' class='parent grandparent'><div id='parent' class='parent child'><div id='child' class='child'></div></div></div>");
ok(true);
});
在这个例子中,当我从Test Explorer运行它们时,两个测试都成功运行,但是如果我选择Analyze Code Coverage,则只有第一个测试通过(这取决于我写的外部文件,但不是jQuery)。 / p>
这是我的chutzpah.json文件:
{
"CodeCoverageExcludes": ["jquery.*", "kendo.core.*.js"]
}
以下是运行coverage时失败测试的错误消息:
Test Name: repro.tests jQuery loaded
Test FullName: c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js::repro.tests::jquery loaded
Test Source: c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js : line 14
Test Outcome: Failed
Test Duration: 0:00:00.001
Result Message: Died on test #1 global code@file:///c:/dev/tfs/mke/web%20applications/internet/companydashboard/dev/companydashboard/companydashboard/tests/_Chutzpah.3bddafd322dddb16ba3a30cb58251b28.test.html:51:5
appendChild@[native code]: Can't find variable: $ Expected: undefined, Actual: null
Result StackTrace: at repro.tests jQuery loaded in c:\dev\tfs\mke\web applications\internet\companydashboard\dev\companydashboard\companydashboard\tests\test.js:line 14
答案 0 :(得分:0)
在chutzpah.json文件中,在列出这些依赖项(如jquery)时的references部分中。确保设置属性&#34; IsTestFrameworkFile:true&#34;。这应该会有所帮助。