将结果保存在Azure DevOps中的vscode-extension单元测试文件中

问题描述 投票:0回答:1

我有一个问题,再次......

我尝试从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.似乎我限制如何创建一个记者/ testrunner或其他...我不明白。

提供的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”模块的文档

visual-studio-code mocha vscode-extensions test-runner
1个回答
-1
投票
let a: any = {
    ui: "tdd",
    reporter: "xunit",
    reporterOptions: {
        output: normalize(join(getExtensionRootPath(), "..", "TestResults", "unit-tests", os + ".xml")),
    }        
};

testRunner.configure(a);

这对我来说除了Linux之外我会编辑这个答案,如果也为Linux管理它。

© www.soinside.com 2019 - 2024. All rights reserved.