Hi,
I'm new to C# and trying to write a simple GUI Unit Test with NUnit and NUnitForms. I want to test if a click on a button opens a new Form. My application has two forms, the main form (Form1) with a button that opens a new form (Password):
private void button2_Click(object sender, EventArgs e)
{
Password pw = new Password();
pw.Show();
}
The source for my Test looks like this:
using NUnit.Framework;
using NUnit.Extensions.Forms;
namespace Foobar
{
[TestFixture]
public class Form1Test : NUnitFormTest
{
[Test]
public void TestNewForm()
{
Form1 f1 = new Form1();
f1.Show();
ExpectModal("Enter Password", "CloseDialog");
// Check if Button has the right Text
ButtonTester bt = new ButtonTester("button2", f1);
Assert.AreEqual("Load Game", bt.Text);
bt.Click();
}
public void CloseDialog()
{
ButtonTester btnClose = new ButtonTester("button2");
btnClose.Click();
}
}
}
The NUnit output is:
NUnit.Extensions.Forms.FormsTestAssertionException : expected 1 invocations of modal, but was invoked 0 times (Form Caption = Enter Password)
The Button Text check is successfull. The problem is the ExpectModal method. I've also tried it with the Form's name but without success.
Does anyone know what might be wrong?