大家好,我有一个关于 NUnit 扩展(2.5.10)的问题。我想要做的是向数据库写入一些额外的测试信息。为此,我使用事件侦听器创建了 NUnit 扩展。我遇到的问题是 public void TestFinished(TestResult result) 方法在运行时被调用了两次。我写入数据库的代码就是这种方法,这让我在数据库中留下了重复的条目。问题是:这是预期的行为吗?我能做点什么吗?扩展代码如下。谢谢。
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){}
}
}