我试图让Chutzpah的VS 2013测试资源管理器识别QUnit测试,同时我将require.js与knockoutjs结合使用
我已经找到了下面列出的一些好资源,但我想我必须有一个缺失的部分。
This is what I used以确保我正确使用Qunit和require.js.
From this resource,听起来我也需要一个Chutzpah.json文件。
以下是我可以重现的内容:
示例:testThatWorks.js
test("test that shows up in test explorer", function () {
equal("444test", "444test");
});
示例:testThatAlsoWorks.js
define(
function () {
test("Test that also shows up in test explorer.", function () {
equal("444test", "444test");
});
});
示例:testThatDoesn&#t; 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;消息:无头浏览器返回错误:执行测试文件时发生超时
答案 0 :(得分: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/214和https://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"}
]
}