我有一个具有超过8000个测试的测试套件,并且很难看到代码更改之间哪些测试中断(这些测试用例是从某些日志文件中自动提取的查询)。
是否有一种简单的方法可以获取NUnit运行的失败测试列表?理想情况下,我想比较哪些测试在运行之间受到影响。
答案 0 :(得分:3)
您可以实施NUnit.Core.Extensibility.IAddin'和' NUnit.Core.EventListener'。因此,您可以操纵测试结果。 NUnit(2.5或更高版本)将自动加载实现" IAddin方法的类。"
喜欢那样:
using System;
using System.Text;
using NUnit.Core.Extensibility;
using NUnit.Core;
namespace YourNUnitAddIns
{
/// <summary>
/// Coleta informacoes da execucao do NUnit.
/// </summary>
[NUnitAddin(
Name="CollectNUnitFailAddIn",
Description="do something",
Type=ExtensionType.Core)]
public class CollectNUnitFailAddIn : IAddin, EventListener
{
#region IAddin Members
public bool Install(IExtensionHost host)
{
IExtensionPoint suiteBuilders = host.GetExtensionPoint("SuiteBuilders");
IExtensionPoint testBuilders = host.GetExtensionPoint("TestCaseBuilders");
IExtensionPoint events = host.GetExtensionPoint("EventListeners");
if (events == null)
return false;
events.Install(this);
return true;
}
#endregion
#region EventListener Members
public void RunFinished(Exception exception)
{
//do something here.
}
public void RunFinished(TestResult result)
{
//do something here.
}
public void RunStarted(string name, int testCount)
{
//do something here.
}
public void SuiteFinished(TestResult result)
{
//do something here.
}
public void SuiteStarted(TestName testName)
{
//do something here.
}
public void TestFinished(TestResult result)
{
//do something here.
}
public void TestOutput(TestOutput testOutput)
{
//do something here.
}
public void TestStarted(TestName testName)
{
//do something here.
}
public void UnhandledException(Exception exception)
{
//do something here.
}
#endregion
}
}
答案 1 :(得分:1)
您应该可以从NUnit的Xml输出中通过简单的xslt转换获得结果。
像CruiseControl这样的持续集成工具已经为此构建了XSLT翻译。
https://github.com/ccnet/CruiseControl.NET/blob/master/project/xsl/AlternativeNUnitDetails.xsl