ExpectModal() on exception throw. Possible?

Phil T.
  • Phil T.

    Phil T. - 2007-05-22


    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 :

    AppForm.cs :

            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);

    AppFormTest.cs :

            public void Test()
                ExpectModal("AlternateAppForm", "TestFormHandler");
                new AppForm((IAppController)controller.MockInstance).Show();
                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!?

    Thank you.

    • mladenp

      mladenp - 2007-06-27

      try using MouseController to simulate the mouse click on the button.

      • Phil T.

        Phil T. - 2008-03-14

        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.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks