我已经为 NUnit (2.6.0) 定义了一个插件,如下所示
namespace company.Testing.Attributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ThenWithSetupAttribute : TestAttribute
{}
}
namespace company.Testing
{
[NUnitAddin(Description = "ThenWithSetup", Name = "ThenWithSetup")]
public class ThenWithSetup : IAddin, EventListener
{
public void RunStarted(string name, int testCount)
{}
public void RunFinished(TestResult result)
{}
public void RunFinished(Exception exception)
{}
public void TestStarted(TestName testName)
{
throw new Exception("Hello");
}
public void TestFinished(TestResult result)
{
throw new Exception("I said hello!");
}
public void SuiteStarted(TestName testName)
{}
public void SuiteFinished(TestResult result)
{}
public void UnhandledException(Exception exception)
{}
public void TestOutput(TestOutput testOutput)
{}
public bool Install(IExtensionHost host)
{
IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
if (listeners == null)
return false;
listeners.Install(this);
return true;
}
}
}
使用Visual Studio 2010和ReSharper 7,我的印象是,当我还设置了ReSharper -> Options-> Nunit -> Load NUnit Addins -> ALWAYS并放置公司时。测试.dll在..\ReSharper\v7.0\Bin\addins 文件夹,这些事件侦听器将触发(在这种情况下引发异常)。但是,情况并非如此,当测试在 TestStarted-eventlistener 中失败时,测试会成功运行?!
我的测试,在另一个解决方案中定义(参考上述.dll):
[ThenWithSetup]
public void ShouldGetOkResponse()
{
Console.WriteLine("testing 123");
Assert.AreEqual(HttpStatusCode.OK, _result.StatusCode);
}
我显然错过了一些东西,但是什么?
谢谢!
可能是您的测试dll包含插件的nunit包?对我来说,这种情况不起作用。删除包后,所有开始工作。
看看我的答案:https://stackoverflow.com/a/34154702/908936