Automatically expect dialogs when construct a FormTester

Jan 9, 2009 at 9:11 AM
Edited Jan 12, 2009 at 4:28 AM
One of the users complained to me that his unit test code has no response sometimes while he did some code changes. I found that his changes caused a form popping up a dialog window while it did not before. If he did not update his test code for this form the dialog will be there until someone close. It has interrupted his job as it's difficult to him to know which parts would be encountered while he did some changes. I think he's right, unit test should take the responsibility for checking the relevant parts of the changes but not "no response".

Hence I've added another constructor of FormTester class. It has 2 parameters one this the instance of the form need to be tested as before, the other one is a bool which indicates whether you want to begin to expect the dialogs at once. If you were afraid that this form will brings some dialogs up in the future please set True here. After that you don't need to call BeginExpectation explicitly as it had been executed within the constructor. In the future if any dialogs bring up here by some changes this unit test will throw an exception instead of "no response". And if you want to add the expectation you can access with the propoerty named "DialogExpectation" of the instance of FormTestser.

Regarding the sample please refer to the code belongs to the test project in class DialogExpectationFacts, methods AutoExpectDialogWhenConstructFormTester_Expected and AutoExpectDialogWhenConstructFormTester_Unexpected_ExceptionThrough.

As the dialog expectation need to be disposed manually if you start it within the constructor it will be terminated within the destructor which will reduce the performance a bit so if you are pretty sure the windows those will not be able to bring dialog up please use the original constructor without bool parameter or just set it as False.