File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes JUnit: recognise that a MessageBox pops up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit: recognise that a MessageBox pops up" Watch "JUnit: recognise that a MessageBox pops up" New topic

JUnit: recognise that a MessageBox pops up

Steffen Mezger

Joined: May 11, 2006
Posts: 1

i have to test a function which opens a Messagebox at the end of the code. And because that the Junit test will stop until anybody clicks "OK" on the messagebox. Thats not good, because nobody is near the PC during the test...

How can i solve this problem ? Are there any possibilities to close that box automaticly or terminate the new window ??

Thanks !

Best regards,
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
There are at least two solutions:

- use an extension to JUnit, such as Jemmy, to actually check that the box is there, and to click the close button, or

- introduce an indirection, so that you can mock the method call that opens the message box

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: JUnit: recognise that a MessageBox pops up
It's not a secret anymore!