3

当我的夜间构建完成时,我会自动运行一些 NUnit 测试。我有一个控制台应用程序,它检测新构建,然后将构建的 MSI 复制到本地文件夹,并将我的所有组件部署到测试服务器。之后,我在 NUnit dll 中有一堆测试,我通过使用 Process/ProcessStartInfo 执行“nunit-console.exe”来运行这些测试。我的问题是,如何以编程方式获得完全成功/失败测试的数字?

4

4 回答 4

3

您是否考虑过使用像 CruiseControl.NET 这样的持续集成服务器?

它为您构建和运行测试,并在网页中显示结果。如果您只想要一个工具,请nunit-console.exe以 XML 格式输出结果,并使用 XSLT 脚本解析/转换它,就像来自巡航控制系统的脚本一样。

这是这样一个 XSL 文件的示例,如果您在直接输出上运行转换,nunit-console.exe那么您将不得不调整选择语句并删除 Cruisecontrol。

但是,听起来您可能对持续集成感兴趣。

于 2010-06-11T18:38:52.163 回答
1

我们有类似的需求,我们所做的就是读入 NUnit 生成的测试结果 XML 文件。

XmlDocument testresultxmldoc = new XmlDocument();
testresultxmldoc.Load(this.nunitresultxmlfile);

XmlNode mainresultnode = testresultxmldoc.SelectSingleNode("test-results");
this.MachineName = mainresultnode.SelectSingleNode("environment").Attributes["machine-name"].Value;
int ignoredtests = Convert.ToInt16(mainresultnode.Attributes["ignored"].Value);
int errors = Convert.ToInt16(mainresultnode.Attributes["errors"].Value);
int failures = Convert.ToInt16(mainresultnode.Attributes["failures"].Value);
int totaltests = Convert.ToInt16(mainresultnode.Attributes["total"].Value);
int invalidtests = Convert.ToInt16(mainresultnode.Attributes["invalid"].Value);
int inconclusivetests = Convert.ToInt16(mainresultnode.Attributes["inconclusive"].Value);
于 2012-06-27T13:03:13.800 回答
0

我将引用nunit 2.4.3 的发行说明

控制台运行程序现在对尝试运行测试时遇到的错误使用负返回码。测试本身的失败或错误会给出与此类失败或错误的数量相等的正返回代码。

(强调我的)。这里的含义是,与 bash 中通常一样,返回 0 表示成功,非零表示失败或错误(如上)。

高温高压

于 2015-02-02T17:20:22.547 回答
0

我们最近有一个类似的需求,并编写了一个小型开源库来将结果文件组合成一个聚合结果集(就像您使用一次 nunit-console 运行了所有测试一样)。

你可以在https://github.com/15below/NUnitMerger找到它

于 2012-06-25T08:26:02.217 回答