2012-08-16 35 views
2

我喜歡這樣使用NUnit事件偵聽器加載項與ReSharper的7

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

定義一個插件用於NUnit的(2.6.0)使用Visual Studio 2010和ReSharper的7我是,當我的印象還設置了ReSharper - > Options-> Nunit - >加載NUnit Addins - > Always並將company.Testing.dll放入.. \ ReSharper \ v7.0 \ Bin \ addins文件夾中,那些eventlisteners會觸發(拋出異常這個案例)。然而,情況並非如此,當TestStarted-eventlistener失敗時,測試運行成功!!!

我的測試,在另一種解決方案定義(referenceing上述.dll文件):

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

我失去了一些東西很明顯,但什麼?

謝謝!

+0

你是否找到了解決這個問題的方法? – SergSW 2013-03-23 04:01:01

+0

對不起,我沒有 – Andreas 2013-04-18 06:59:19

回答