如何使用Cake(C#make)脚本在xunit中通过和失败测试用例计数 [英] How to get passed and fail test case count in xunit using cake(c# make) script

查看:112
本文介绍了如何使用Cake(C#make)脚本在xunit中通过和失败测试用例计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用cake脚本运行使用cake脚本以Xunit编写的测试用例,我需要知道通过和失败的测试用例的数量。

I try to use the cake script for running the test cases written in Xunit using the cake script , I need to know the number of passed and failed test cases count.

#tool "nuget:?package=xunit.runner.console"
var testAssemblies = GetFiles("./src/**/bin/Release/*.Tests.dll");
XUnit2(testAssemblies);

参考: http://www.cakebuild.net/dsl/xunit-v2

有人可以建议如何获得通过和失败的测试用例的数量 ??

Can anyone please suggest how to get the number of passed and failed test cases?

推荐答案

您必须使用 XUnit2Aliases.XUnit2(IEnumerable< FilePath>,XUnit2Settings) + XmlPeekAliases 来读取XUnit输出。

You'll have to use XUnit2Aliases​.XUnit2(IEnumerable < FilePath >, ​XUnit2Settings) + XmlPeekAliases for reading the XUnit output.

var testAssemblies = GetFiles("./src/**/bin/Release/*.Tests.dll");
XUnit2(testAssemblies,
     new XUnit2Settings {
        Parallelism = ParallelismOption.All,
        HtmlReport = false,
        NoAppDomain = true,
        XmlReport = true,
        OutputDirectory = "./build"
    });

xml格式为:( XUnit文档示例源有关Reflex的更多信息

The xml format is:(XUnit documentation, the example source, more information in Reflex)

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="nosetests" tests="1" errors="1" failures="0" skip="0">
    <testcase classname="path_to_test_suite.TestSomething"
              name="test_it" time="0">
        <error type="exceptions.TypeError" message="oops, wrong type">
        Traceback (most recent call last):
        ...
        TypeError: oops, wrong type
        </error>
    </testcase>
</testsuite>

然后,以下代码段将为您带来信息:

Then the following snippet should bring you the information:

var file = File("./build/report-err.xml");
var failuresCount = XmlPeek(file, "/testsuite/@failures");
var testsCount = XmlPeek(file, "/testsuite/@tests");
var errorsCount = XmlPeek(file, "/testsuite/@errors");
var skipCount = XmlPeek(file, "/testsuite/@skip");

这篇关于如何使用Cake(C#make)脚本在xunit中通过和失败测试用例计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆