NUnit扩展 [英] NUnit extension

查看:150
本文介绍了NUnit扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个关于NUnit Extension(2.5.10)的问题. 我正在尝试做的是将一些额外的测试信息写入 数据库.为此,我使用事件创建了NUnit扩展 听众. 我遇到的问题是公众无效 TestFinished(TestResult result)方法在处被调用两次 运行.我写到数据库的代码就是这种方法 这给我留下了数据库中重复的条目.这 问题是:这是预期的行为吗?我可以做点什么 它? 扩展代码如下.谢谢.

Hi All i have a question regarding NUnit Extension (2.5.10). What i am trying to do is write some additional test info to the database. For that i have created NUnit extension using Event Listeners. The problem i am experiencing is that public void TestFinished(TestResult result) method is being called twice at runtime. And my code which writes to the database is in this method and that leaves me with duplicate entries in the database. The question is: Is that the expected behaviour? Can i do something about it? The extension code is below. Thanks.

using System;
using NUnit.Core;
using NUnit.Core.Extensibility;

namespace NuinitExtension
{
[NUnitAddinAttribute(Type = ExtensionType.Core,
                     Name = "Database Addin", 
                     Description = "Writes test results to the database.")]
public class MyNunitExtension : IAddin, EventListener
{
    public bool Install(IExtensionHost host)
    {
        IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
        if (listeners == null)
            return false;

        listeners.Install(this);
        return true;
    }

    public void RunStarted(string name, int testCount){}
    public void RunFinished(TestResult result){}
    public void RunFinished(Exception exception){}
    public void TestStarted(TestName testName){}

    public void TestFinished(TestResult result)
    {
        // this is just sample data
        SqlHelper.SqlConnectAndWRiteToDatabase("test", test", 
                                               2.0, DateTime.Now);
    }

    public void SuiteStarted(TestName testName){}
    public void SuiteFinished(TestResult result){}
    public void UnhandledException(Exception exception){}
    public void TestOutput(TestOutput testOutput){}
}

}

推荐答案

我已经设法通过删除扩展名来解决此问题 NUnit 2.5.10 \ bin \ net-2.0 \ addins文件夹中的程序集.在这一刻 一切正常,但我不确定如何.我以为你 必须在addins文件夹内具有扩展/插件程序集. 我正在通过NUnit.exe打开解决方案来运行测试.我的延伸 项目是我正在测试的解决方案的一部分.我也向NUnit的人提出了这个问题,并得到了以下解释:

I have managed to fix the issue by simply removing my extension assembly from NUnit 2.5.10\bin\net-2.0\addins folder. At the moment everything works as expected but i am not sure how. I thought that you have to have the extension/addin assembly inside the addins folder. I am running tests by opening a solution via NUnit.exe. My extension project is part of the solution i am testing. I have also raised this issue with NUnit guys and got the following explanation:

您的插件最有可能被加载了两次.为了使测试插件更加容易,NUnit除了搜索addins目录之外,还在每个测试程序集中搜索要加载的插件.通常,当您确定外接程序可以正常工作时,应将其从测试程序集中删除,并将其安装在addins文件夹中.这使其可用于使用NUnit运行的所有测试. OTOH,如果您确实只希望将该插件应用到某个项目,则可以将其保留在测试程序集中,而不必将其作为永久插件安装. http://groups.google.com/group/nunit -discuss/browse_thread/thread/c9329129fd803cb2/47672f15e7cc05d1#47672f15e7cc05d1

Most likely, your addin was being loaded twice. In order to make it easier to test addins, NUnit searches each test assembly for addins to be loaded, in addition to searching the addins directory. Normally, when you are confident that your addin works, you should remove it from the test assembly and install it in the addins folder. This makes it available to all tests that are run using NUnit. OTOH, if you really only want the addin to apply for a certain project, then you can leave it in the test assembly and not install it as a permanent addin. http://groups.google.com/group/nunit-discuss/browse_thread/thread/c9329129fd803cb2/47672f15e7cc05d1#47672f15e7cc05d1

这篇关于NUnit扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆