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);
Reference : http://www.cakebuild.net/dsl/xunit-v2
Can anyone please suggest how to get the number of passed and failed test cases?
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"
});
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");