2017-05-10 76 views
1

我一直在用NUnitForms搞亂,我遇到了一個簡單測試的障礙。我將在下面提供更多信息,但是要簡要總結一下問題,我處於一種狀態,即需要繼承NUnitFormTest類才能使用ExpectModal功能,但這會導致無法找到測試(使用NUnit 3.6.1) 。如果我降級到NUnit版本2.x,則會發現測試,但我在TearDown函數中發現錯誤。有什麼我在這裏失蹤?NUnit-Console在NUnit 3.x中找不到用於NUnitForms測試的測試裝置

現在,完整的信息,請參閱下面...

我的測試最初引用NUnit 3.6.1,是這樣的:

using EnterpriseManager; 
using NUnit.Extensions.Forms; 
using NUnit.Framework; 

namespace ManagerTests 
{ 
    [TestFixture] 
    public class ManagerTests 
    { 
     [Test] 
     public void ConnectTest() 
     { 
      ConnectForm form = new ConnectForm(); 
      form.Show(); 

      ButtonTester testButton = new ButtonTester("TestConnectionButton", "ConnectForm"); 
      testButton.Click(); 

      LabelTester testLabel = new LabelTester("StatusLabel", "ConnectForm"); 
      Assert.AreEqual("Connection successful", testLabel.Text); 
     } 
    } 
} 

在我上面的初步測試,我不是從NUnitFormTest繼承類(當時並沒有意識到),但即使缺少了,我的測試可以通過Visual Studio的測試瀏覽器找到,我可以通過nunit3-console應用程序(已通過)運行我的測試。

最終我擴展了我的測試來調用一個模式對話框,這對我造成了問題,但最終我讀了ExpectModal功能,這導致我添加NUnitFormTest繼承。測試成爲以下內容:

using EnterpriseManager; 
using NUnit.Extensions.Forms; 
using NUnit.Framework; 

namespace ManagerTests 
{ 
    [TestFixture] 
    public class ManagerTests : NUnitFormTest 
    { 
     [Test] 
     public void ConnectTest() 
     { 
      ConnectForm form = new ConnectForm(); 
      form.Show(); 

      ButtonTester testButton = new ButtonTester("TestConnectionButton", "ConnectForm"); 
      testButton.Click(); 

      LabelTester testLabel = new LabelTester("StatusLabel", "ConnectForm"); 
      Assert.AreEqual("Connection successful", testLabel.Text); 

      ExpectModal("ConnectToServer", delegate { 
       LabelTester label = new LabelTester("ConnectStatusLabel", "ConnectToServer"); 
       Assert.AreEqual("Connected", label.Text); 
      }); 

      // Launch the modal dialog 
      ButtonTester connectButton = new ButtonTester("ConnectToServerButton", "ConnectForm"); 
      connectButton.Click(); 
     } 
    } 
} 

這是問題出現的地方。在添加NUnitFormTest類的繼承之後,Visual Studio和nunit3-console.exe都未檢測到任何測試。我認爲這可能與所引用的NUnit版本有關,所以我降級到了各種2.x版本。這讓Visual Studio來檢測測試(雖然nunit3-console.exe保持報告「不確定」的結果),但所有的測試會失敗,出現錯誤:

Result StackTrace: 
--TearDown 
at NUnit.Extensions.Forms.Desktop.Destroy() 
at NUnit.Extensions.Forms.NUnitFormTest.Verify() 
Result Message: TearDown : System.ComponentModel.Win32Exception : The requested resource is in use 

我已經下解決此問題的一些搜索,但一切我發現好像建議這是以前遇到的NUnit問題,這個問題在某些時候已經修復(不要引用我)。所以現在我處於一個狀態,我需要繼承NUnitFormTest類以使用ExpectModal功能,但這會導致無法找到測試。然而,如果我移動到NUnit版本2.x,我在TearDown函數上遇到問題。有什麼我在這裏失蹤?

+0

目前無法嘗試此操作,但解決TearDown問題的潛在解決方法是重寫位於NUnitFormTest中的UseHidden屬性以返回false。 – ajg

+0

任何想法,如果有一種已知的方法來使用「NUnitForms」與'NUnit 3.x'或只能使用版本2.x? – Fizz

+0

不知道我害怕,因爲我使用它的年齡,它看起來好幾年沒有釋放。 – ajg

回答

1

NUnitForms多年未更新,因此它仍然依賴於NUnit V2。當你從NUnitFormTest派生的時候,你使用的是NUnit 2.6.2,不管你認爲你已經安裝了什麼,因爲代碼與NUnit版本緊密結合。

NUnitForms可以很容易地更新到NUNit 2.6.4,但除此之外,這是一個更大的變化,甚至可能需要重寫。

順便說一句,盧克在很久之前就把我加入了這個項目,但我還沒有活躍起來。我曾經希望能夠用NUnit 3編寫它的一個版本,但是我懷疑是否有更多的需求來測試Windows窗體。

您應該從您的解決方案中刪除NUnit框架的所有包,並引用與NUnitForms一起安裝的版本。如果你想嘗試不同的版本,它們應該是NUnitForms版本,這樣你的測試和NUnitForms都引用了NUnit的同一個副本。

+0

好的謝謝你的信息,這爲我清除了一些東西。 – Fizz