简体   繁体   English

从Nunit获取失败的测试列表

[英]Get list of failing tests from Nunit

I have a testsuite with over 8000 tests and it's getting really hard seeing which tests broke between code changes (these test cases are queries that were automatically extracted from some log files). 我有一个测试套件,其中包含8000多个测试,要查看在代码更改之间哪些测试中断确实很难(这些测试用例是从某些日志文件中自动提取的查询)。

Is there a simple way to get the list of failing tests for a NUnit run? 是否有一种简单的方法来获取NUnit运行失败测试的列表? Ideally, I'd like to compare which tests were affected between runs. 理想情况下,我想比较两次运行之间哪些测试受到了影响。

You can implement 'NUnit.Core.Extensibility.IAddin' and 'NUnit.Core.EventListener'. 您可以实现“ NUnit.Core.Extensibility.IAddin”和“ NUnit.Core.EventListener”。 So you can manipulate the results of your tests. 这样您就可以操纵测试结果。 The NUnit (2.5 or higher) will automatically load your class that implements the methods of "IAddin." NUnit(2.5或更高版本)将自动加载实现“ IAddin”方法的类。

Like that: 像那样:

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
    }
}

You should be able to get the results from a simple xslt translation from NUnit's Xml output. 您应该能够从NUnit的Xml输出中通过简单的xslt转换获得结果。

Continuous integration tools like CruiseControl have XSLT translations already built for this. 诸如CruiseControl之类的持续集成工具已经为此构建了XSLT转换。

https://github.com/ccnet/CruiseControl.NET/blob/master/project/xsl/AlternativeNUnitDetails.xsl https://github.com/ccnet/CruiseControl.NET/blob/master/project/xsl/AlternativeNUnitDetails.xsl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM