© ThoughtWorks, 2006
Functional Testing Swing
User Interfaces with
Frankenstein
Vivek Prahlad
Senior Developer, ThoughtWorks
© ThoughtWorks, 2006
Agenda
• Why a new tool?
• Introduction to Frankenstein
• Demo
• Q & A
© ThoughtWorks, 2006
Why?
© ThoughtWorks, 2006
Swing Client, pre-existing
FIT scripts
© ThoughtWorks, 2006
Needed to write fixtures for new screens
© ThoughtWorks, 2006
Did not test actual UI
© ThoughtWorks, 2006
Tested UI model layer
© ThoughtWorks, 2006
UI Model
FIT Fixtures Screens
© ThoughtWorks, 2006
No Swing driver
© ThoughtWorks, 2006
Duplication
© ThoughtWorks, 2006
Enter UserName foo
Enter Password bar
Initiate Login
Navigate Create>Blog Entry
...
© ThoughtWorks, 2006
Enter UserName foo
Enter Password bar
Initiate Login
Navigate Edit>Blog Entry
...
© ThoughtWorks, 2006
Not easy to create fixtures
© ThoughtWorks, 2006
Writing fixtures slowed down
development
© ThoughtWorks, 2006
Additional features
© ThoughtWorks, 2006
Record & Play
© ThoughtWorks, 2006
Multithreaded apps?
© ThoughtWorks, 2006
Swing is single threaded
© ThoughtWorks, 2006
but
© ThoughtWorks, 2006
Serious Swing apps use
worker threads
© ThoughtWorks, 2006
© ThoughtWorks, 2006
© ThoughtWorks, 2006
What's the problem?
© ThoughtWorks, 2006
Tests with arbitrary waits
© ThoughtWorks, 2006
click_button(“connect”)
wait(20) //Pray!
do_something_else
© ThoughtWorks, 2006
Fragile,slow tests
© ThoughtWorks, 2006
Explicit Synchronization
© ThoughtWorks, 2006
wait_for_text(“done”)
© ThoughtWorks, 2006
Verbose tests
© ThoughtWorks, 2006
upload_file(“file”)
wait_for_text(“done”)
© ThoughtWorks, 2006
Obscures intent
© ThoughtWorks, 2006
Custom components?
© ThoughtWorks, 2006
Evaluated Abbot, Marathon
© ThoughtWorks, 2006
Didn't quite have what we'd
wanted
© ThoughtWorks, 2006
'Let's write it!'
-Chris Stevenson
© ThoughtWorks, 2006
Introducing Frankenstein
© ThoughtWorks, 2006
© ThoughtWorks, 2006
FIT like scripts
© ThoughtWorks, 2006
Navigate Create>Blog
EnterText post *my blog text*
SelectDropDown time now
ClickButton Post
© ThoughtWorks, 2006
Plain text
© ThoughtWorks, 2006
Easy to write, Human Readable
© ThoughtWorks, 2006
Human Readable
© ThoughtWorks, 2006
Human Readable
© ThoughtWorks, 2006
Understood (and shared) by the whole team
© ThoughtWorks, 2006
Record & Playback
© ThoughtWorks, 2006
..useful for reproducing bugs
© ThoughtWorks, 2006
No arbitrary waits
© ThoughtWorks, 2006
Works with JDK 1.4+
© ThoughtWorks, 2006
Code changes?
© ThoughtWorks, 2006
Name components with component.setName()
© ThoughtWorks, 2006
Works with applications where codebase cannot be
modified
© ThoughtWorks, 2006
...with a few limitations
© ThoughtWorks, 2006
Not easy record custom components
© ThoughtWorks, 2006
i18n
© ThoughtWorks, 2006
Test multithreaded apps viaWorkerThreadMonitor
© ThoughtWorks, 2006
public interface WorkerThreadMonitor {
public void start();
public void waitForIdle();//blocking
}
© ThoughtWorks, 2006
© ThoughtWorks, 2006
How is the WorkerThreadMonitor used?
© ThoughtWorks, 2006
Wait for all Swing events to be completed
© ThoughtWorks, 2006
Wait for all worker threads to complete
© ThoughtWorks, 2006
Easy to extend test vocabulary
© ThoughtWorks, 2006
Add assertions
© ThoughtWorks, 2006
Easy integration
© ThoughtWorks, 2006
java com.yourapp.MainClass args...
© ThoughtWorks, 2006
java com.thoughtworks.frankenstein.application.PipingMain com.yourapp.MainClass args...
© ThoughtWorks, 2006
..or write your own main class
© ThoughtWorks, 2006
Custom recorders for custom components
© ThoughtWorks, 2006
Ruby driver
© ThoughtWorks, 2006
Variables, functions
© ThoughtWorks, 2006
Keep tests DRY
© ThoughtWorks, 2006
Other language drivers easy to add
© ThoughtWorks, 2006
~ 1500 LOC
© ThoughtWorks, 2006
98% test coverage
© ThoughtWorks, 2006
Demo
© ThoughtWorks, 2006
How does it work?
© ThoughtWorks, 2006
Recorders hook onto Swing Event Queue
© ThoughtWorks, 2006
Add component-specific listeners
© ThoughtWorks, 2006
Create Events when listeners are triggered
© ThoughtWorks, 2006
Events know how to replay themselves
© ThoughtWorks, 2006
IOC + PicoContainer
© ThoughtWorks, 2006
What's missing?
© ThoughtWorks, 2006
More assertions
© ThoughtWorks, 2006
Support for relatively less used components
© ThoughtWorks, 2006
Open Sourcing soon
© ThoughtWorks, 2006
Thank You