我又遇到问题了。。。
我试图从Azure DevOps中的持续集成测试中制作一份测试报告。我编写了单元测试,如中所述:
https://code.visualstudio.com/api/working-with-extensions/testing-extension
我写yml的大部分内容如下:
https://code.visualstudio.com/api/working-with-extensions/continuous-integration
现在我想"公布"我的测试结果。。。我认为要发布它们,我必须以以下格式之一创建一个XML(或TRX):JUnit、NUnit 2、NUnit 3、Visual Studio Test(TRX)和xUnit 2。我似乎被限制了如何创建一个记者/测试者或其他什么。。。我不明白。
提供的vscode的API看起来像:
testRunner.configure({
ui: "tdd",
useColors: true
});
module.exports = testRunner;
API的预期类型为:
interface MochaSetupOptions {
//milliseconds to wait before considering a test slow
slow?: number;
// timeout in milliseconds
timeout?: number;
// ui name "bdd", "tdd", "exports" etc
ui?: string;
//array of accepted globals
globals?: any[];
// reporter instance (function or string), defaults to `mocha.reporters.Dot`
reporter?: any;
// bail on the first test failure
bail?: boolean;
// ignore global leaks
ignoreLeaks?: boolean;
// grep string or regexp to filter tests with
grep?: any;
// colored output from test results
useColors?: boolean;
// causes test marked with only to fail the suite
forbidOnly?: boolean;
}
我认为我最好的尝试是使用该模块https://www.npmjs.com/package/mocha-junit-reporter:
testRunner.configure({
reporter: 'mocha-junit-reporter',
reporterOptions: {
mochaFile: './path_to_your/file.xml'
}
});
我知道它不适合所描述的API,但当你看到vscode-module:的源代码时
function configure(opts) {
mocha = new Mocha(opts);
}
exports.configure = configure;
因此,它符合"mocha junit reporter"模块的文档
let a: any = {
ui: "tdd",
reporter: "xunit",
reporterOptions: {
output: normalize(join(getExtensionRootPath(), "..", "TestResults", "unit-tests", os + ".xml")),
}
};
testRunner.configure(a);
这是为我做的,除了Linux,如果我也为Linux管理它,我会编辑这个答案。