2

我正在尝试使用 Chutzpah 让 VS 2013 测试资源管理器识别 QUnit 测试,同时我将 require.js 与 knockoutjs 结合使用

我发现下面列出了一些很好的资源,但我认为我必须只缺少一个。

这是我可以重现的内容:

  • 如果我只使用 Chutzpah 和 qunit,我可以让它工作,所以我知道我已经为 VS 测试运行器正确安装了 Chutzpah。

示例:testThatWorks.js

        test("test that shows up in test explorer", function () {
            equal("444test", "444test");
        });
  • 如果在浏览器中查看 index.html,它会以正确的结果运行我的测试。
  • 如果我使用定义语法它也可以

示例:testThatAlsoWorks.js

define(
function () {

    test("Test that also shows up in test explorer.", function () {
        equal("444test", "444test");
    });

});
  • 如果我使用 require 语法来包含任何其他资源,它会失败(这会加载淘汰赛但实际上并没有使用它)

示例:testThatDoesn'tWork.js

define(['knockout'],
function (ko) {

    test("Test that doesn't show up in test explorer.", function () {
        equal("444test", "444test");
    });
});

这是 VS 2013 测试资源管理器显示的内容:

在此处输入图像描述

这是相关的项目设置(我的真实项目还有其他文件,但我在这里尽量保持简单):

index.html (think I won't need this once I get it working in VS test runner)
tests
   references
      qunit.css
      qunit.js
      qunit.html
   chutzpah.json
   unittestsmain.js (think I won't need this once I get it working in VS test runner)
   testThatWorks.js
   testThatDoesntWork.js
   testThatAlsoWorks.js
Scripts
   jquery stuff
   require.js stuff
   knockout stuff
   ...

这是我的 chutzpah.json

{
   "Framework": "qunit",
   "TestHarnessReferenceMode": "AMD",
   "TestHarnessLocationMode": "SettingsFileAdjacent",
   "References" : [
      {"Path" : "../Scripts/require.js" }
   ]
}

这是 Chutzpah.log 文件中的超时错误

错误:错误:在运行时执行测试文件时发生超时:c:\workingfoldertfs\lesa-it\developers\whitezelb\chutzpahexample\chutzpahexample\chutzpahexample\tests\testthatdoesntwork.js vstest.executionengine.x86.exe 错误:0:时间: 12:45:01.2839495;线程:34;消息:无头浏览器返回错误:执行测试文件时发生超时

4

1 回答 1

1

我的错误是由于没有为依赖项使用正确的“路径”引起的。如果 testthatdoesntwork.js 文件更改为:

define(['../Scripts/knockout-3.1.0'],
function (knockout) {
    test("Test that doesn't show up in test explorer.", function () {
        equal("444test", "444test");
    }); 
});

Chutzpah.json 文件看起来像:

{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References" : [
     {"Path" : "../Scripts/knockout-3.1.0.js" },
     {"Path" : "../Scripts/require.js" }

]
}

查看https://chutzpah.codeplex.com/workitem/214https://stackoverflow.com/a/22124292/451736帮助我找出了我遇到的问题。

Chutzpah.json 文件中的引用顺序似乎也很重要,因为其他所有内容都相同,并且 json 文件更改为下面的测试没有显示。

{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"References" : [
     {"Path" : "../Scripts/require.js"} ,
     {"Path" : "../Scripts/knockout-3.1.0.js"}

]
}
于 2014-06-18T21:16:31.627 回答