[TFUI] Temporary Interactive Tests
Phlip <phlipcpp-/[email protected]>
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <[email protected]> |
When a test case temporarily pops up a window, you can
often click on it, drive it, and visually inspect its
results. If you put trace statements or breakpoints in
event handlers, you can trigger them and learn how
those handlers work. This practice helps sharpen
fixtures that Simulate User Input.
The revealFor() method, from the last post, supports
both Principles for MS Windows. Some Toolkits will
make two separate fixtures easier to maintain. Some
operate a real event queue all the time, so both
Temporary Visual Inspections and Interactive Tests
need only halt testing long enough to observe and
interact with the target window.
The code sample in the next post uses Jemmy to test a
Swing application. During a test, target windows
flicker on the screen. Timothy Wall supplied this test
fixture to suspend a test until the alternative event
handler, windowClosing(), resumes it:
public class HelloWorldTestUI
extends TestCase
{
class Flag { boolean flag; }
final Flag flag = new Flag();
public void reveal(final JFrameOperator frame)
throws InterruptedException
{
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
flag.flag = true;
frame.removeWindowListener(this);
}
});
while (!flag.flag)
Thread.sleep(100);
} // by Timothy Wall
public void testIt() throws InterruptedException
{
// Start the application under test.
HelloWorld.main(new String[0]);
final JFrameOperator frame = new
JFrameOperator("Hello, World!");
// Find 1st (0th) JTextField in frame.
JTextFieldOperator textfield = new
JTextFieldOperator(frame, 0);
assertTrue("textfield is enabled",
textfield.isEnabled());
assertTrue("textfield is editable",
textfield.isEditable());
// reveal(frame);
}
}
When you de-comment the reveal(frame) line and run
that test, the target window pops up:
[Hello World _[]X]
| [ ] |
| < push me > | <-- disabled
+-------------------+
You can inspect it and manually test its features.
This helps cross-check that the automated tests remain
on track.
When you close the window (using <Alt+F4>, or clicking
the little X in the upper right corner), the setting
DO_NOTHING_ON_CLOSE prevents the target window from
really closing. Its listener (the Swing equivalent of
an event handler) breaks the looping sleep statement,
permitting the remaining test statements to run.
If the remaining test statements did not run, then
bugs might slip into our process.
=====
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
------------------------ Yahoo! Groups Sponsor --------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~->
To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/TestFirstUserInterfaces/
<*> To unsubscribe from this group, send an email to:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/