I've been messing around with NUnitForms
and I've run into a snag with my simple test. I'll provide more information below but to summarize the question briefly, I'm in a state that I need to inherit from the NUnitFormTest
class to use the ExpectModal
functionality but this causes by tests to not be found (using NUnit 3.6.1). If I downgrade to NUnit
version 2.x the tests are found but I get errors on the TearDown function. Is there something I'm missing here?
Now for full information see below...
My test originally was referencing the NUnit 3.6.1
and was like the following:
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);
}
}
}
In my initial test above, I was not inheriting from the NUnitFormTest
class (was not aware of it at the time) but even though that was missing, my test would be found by Visual Studio's Test Explorer and I could run my test via nunit3-console
application (which passed).
Eventually I expanded my test to invoke a modal dialog which caused problems for me although eventually I read about the ExpectModal
functionality which lead me to adding the NUnitFormTest
inheritance. The test became the following:
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();
}
}
}
This is where the problems began. After adding the inheritance of the NUnitFormTest
class, neither Visual Studio nor nunit3-console.exe
detected any tests. I thought this was maybe related to the version of the referenced NUnit
so I downgraded to various 2.x versions. This allowed Visual Studio to detect the tests (although nunit3-console.exe
kept reporting an "Inconclusive" result) but all the tests would fail with the error:
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
I've down some searching around this issue but everything I found seemed to suggest this was some previously encountered issue with NUnit
that was fixed at some point (don't quote me). So now I'm in a state that I need to inherit from the NUnitFormTest
class to use the ExpectModal
functionality but this causes by tests to not be found. Yet if I move down to NUnit
version 2.x I get problems on the TearDown
function. Is there something I'm missing here?