views:

140

answers:

3

I'm using VS2005 and NUnit.

I would like to know if there is a way to test popups using just NUnit.

button1.click(); <-Find/Assert if the popup window has been opened->

+1  A: 

If you are testing whether the popup window has opened or not, then I suppose you are working for the Browser and not your project :)

This kind of functionality is tested using NMock or Rhino.Mocks, In which a mock object is created which is in tern equivalent of your UI object, and its "mocked" to have functionality of your UI component, which is used to test the functionality you would expect the UI component/object to pass.

nils_gate
A: 

I have used the FindWindowEx and CloseWindow unmanaged functions to automate what you are trying to do which may be suitable if you know, with confidence, the title of the popup window. (I am assuming that this is on a Win32 platform). I used it to test a function that creates a modal dialog and does not return control to the original thread until the dialog has been closed (it asserts that the window is found and closed successfully). This isn't quite NUnit kosher, but it worked for my purposes.

If this sounds useful to you, I can produce a snippet, but it's a fairly specific use case.

Oliver N.
+1  A: 

IMHO, it's generally a bad idea to unit test the UI. The very nature of UIs make them problematic for automated testing. They're fluid, and are changed frequently, much more frequently than other code, in ways that will break any tests. Many automated tests are solvable only by taking image snapshots, which is obviously very brittle. Timing concerns become extremely problematic. And finally, such automation relies on taking control of the entire UI, including I/O devices such as the keyboard and mouse. This means that no other activity can be done on the system while the tests are run for fear of breaking the running tests. It's much better to move as much of the functionality out of the UI as humanly possible (patterns such as Presentation Model help with this) and test that functionality instead.

That said, if you must and/or insist on creating automated tests for the UI, you're best served to use an automation library designed just for this. For WinForms and WPF, White is a good example of such a library.

wekempf