使用NUnit EventListeners Addin和ReSharper 7

时间:2012-08-16 14:02:37

标签: nunit resharper nunit-addins resharper-7.0

我为NUnit定义了一个Addin(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 - >选项 - > Nunit - >加载NUnit Addins - >总是将公司.Testing.dll放在.. \ ReSharper \ v7.0 \ Bin \ addins文件夹中,这些eventlisteners会触发(在这种情况下抛出异常)。但情况并非如此,当TestStarted-eventlistener中的测试失败时,测试成功运行!?!

我的测试,在另一个解决方案中定义(引用上面的.dll):

[ThenWithSetup]
public void ShouldGetOkResponse()
{
    Console.WriteLine("testing 123");
    Assert.AreEqual(HttpStatusCode.OK, _result.StatusCode);
}

我明显错过了什么,但是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

可能是你的dll,测试中包含针对插件的nunit包吗?对我来说,这个案子不起作用。删除包后,所有已开始工作。

在这里查看我的答案:https://stackoverflow.com/a/34154702/908936