JS单元测试未出现在VS 2015测试资源管理器中

时间:2015-07-31 06:29:15

标签: unit-testing typescript visual-studio-2015 qunit chutzpah

我是JavaScript单元测试的新手。我正在尝试测试typescript类,我的测试也是用typescript编写的,有点像下面这样:

/// <reference path="../../typings/qunit/qunit.d.ts" />
import Utility1 = require("../utility");//This is script I want to test.    

test("utility_test",function() {

    ...

    var result = ...;
    var expected = ...;
    equal(result, expected, "Test failed");
})

我正在使用VS 2015安装了chutzpah测试适配器,如图所示here。为了清楚起见,我已将其安装到vs 2015的扩展名:Chutzpah Test Runner Context Menu ExtensionChutzpah Test Adapter for the Test Explorer,并添加了Chutzpah NuGet包。

然而,当我构建我的项目时,测试不会出现在测试资源管理器中。当我尝试从上下文菜单运行测试时,它会因此错误而失败:Error: Error: Called start() outside of a test context while already started

任何人都可以让我知道我哪里出错了吗?

修改 对于寻找带有require.js的解决方案的人来说,this here为我工作。现在我的Chutzpah.json如下所示:

{
    "Framework": "qunit",
    "CodeCoverageExcludes": [ "*/require.config.js" ],
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "TypeScriptModuleKind": "AMD",
    "AMDBaseUrl": "",
    "EnableTestFileBatching": true,
    "Compile": {
        "Mode": "External",
        "Extensions": [ ".ts" ],
        "ExtensionsWithNoOutput": [ ".d.ts" ]
    },
    "References": [
        { "Path": "require.js" },
        { "Path": "require.config.js" },
    ],
    "Tests": [
        { "Path": "jsTests" }
    ]
}

1 个答案:

答案 0 :(得分:4)

Chutzpah no longer bundles the Typescript compiler inside of it (as of version 4). You must tell Chutzpah where to find your generated .js files (or/and how to compile them if you want it to).

See the documentation for the Compile setting as well as these code samples.

Most people will use the external compile mode when working with Visual Studio since VS can compile the .ts files for you and you just need to tell Chutzpah where to find them. That will look like this:

{
  "Compile": {
    "Mode": "External",
    "Extensions": [".ts"],
    "ExtensionsWithNoOutput": [".d.ts"]
   },
  "References": [
    {"Includes": ["*/src/*.ts"], "Excludes": ["*/src/*.d.ts"] }
  ],
  "Tests": [
    { "Includes": ["*/test/*.ts"], "Excludes": ["*/test/*.d.ts"] }
  ]
}
相关问题