我一直在用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
函數上遇到問題。有什麼我在這裏失蹤?
目前無法嘗試此操作,但解決TearDown問題的潛在解決方法是重寫位於NUnitFormTest中的UseHidden屬性以返回false。 – ajg
任何想法,如果有一種已知的方法來使用「NUnitForms」與'NUnit 3.x'或只能使用版本2.x? – Fizz
不知道我害怕,因爲我使用它的年齡,它看起來好幾年沒有釋放。 – ajg