I have an application that shows an error form when any error is thrown from any form of an application. (Every forms has a base form that has an OnError() method)
I want to test that the ErrorForm is showing when an error is thrown on a button click, for example. But the problem is that the error is catched by NUnit instead of the form, probably because the click method is called by the test instead of a real click on the form.. So the ErrorForm never shows up.
Here is a code example :
private void AppForm_Load(object sender, EventArgs e)
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(this.OnError);
private void button1_Click(object sender, EventArgs e)
throw new Exception("Test");
private void OnError(object sender, System.Threading.ThreadExceptionEventArgs e)
AlternateAppForm form2 = new AlternateAppForm(controller);
public void Test()
ButtonTester button = new ButtonTester("button1");
private void TestFormHandler()
FormTester formTester = new FormTester("AlternateAppForm");
I dont't know if it's more a NUnit question than a NUnitForms question, but I wanted to try it here anyway. I don't know much about AppDomain/TestDomain, but maybe it could be beacause of that.. Does domebody has an idea on this? Or maybe is't not a good idea to test that!?
try using MouseController to simulate the mouse click on the button.
Better late than never, but it works! Instead of having the exception break in the test, the modal error form is catching it. After that, I just have to close the ErrorForm with an ExpectModal handler.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.