您必須使用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");
您是指測試報告還是您希望將這些值用於其他內容? – Nkosi
@Nkosi XUnit2(testAssemblies);這一行將運行所提到的DLL中的測試用例 – Venkat
@Nkosi我想獲得測試用例運行摘要,例如失敗計數,通過測試用例計數,或者甚至只是代碼級別通過或失敗 – Venkat