加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何使用cake(c#make)脚本在xunit中传递和失败测试用例计数

发布时间:2020-12-16 05:38:34 所属栏目:百科 来源:网络整理
导读:我尝试使用cake脚本运行使用cake脚本在Xunit中编写的测试用例,我需要知道传递的数量和失败的测试用例数. #tool "nuget:?package=xunit.runner.console"var testAssemblies = GetFiles("./src/**/bin/Release/*.Tests.dll");XUnit2(testAssemblies); 参考:ht
我尝试使用cake脚本运行使用cake脚本在Xunit中编写的测试用例,我需要知道传递的数量和失败的测试用例数.
#tool "nuget:?package=xunit.runner.console"
var testAssemblies = GetFiles("./src/**/bin/Release/*.Tests.dll");
XUnit2(testAssemblies);

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

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

解决方法

您必须使用 XUnit2Aliases?.XUnit2(IEnumerable < FilePath >,?XUnit2Settings) XmlPeekAliases来读取XUnit输出.
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 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>

然后,以下代码段应该为您提供以下信息:

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");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读