rich gui testing: swing and javafx

32
Rich GUI Testing Made Easy Functional Testing of Swing and JavaFX GUIs Yvonne Wang Price Guidewire Alex Ruiz Oracle tweet: @alexRuiz

Upload: alex-ruiz

Post on 05-Dec-2014

3.014 views

Category:

Documents


1 download

DESCRIPTION

JavaOne 2010 presentation about functional testing of rich, java-based user interfaces written in Swing and JavaFX

TRANSCRIPT

Page 1: Rich GUI Testing: Swing and JavaFX

Rich GUI Testing Made EasyFunctional Testing of Swing and JavaFX GUIs

Yvonne Wang PriceGuidewire

Alex RuizOracletweet: @alexRuiz

Page 2: Rich GUI Testing: Swing and JavaFX

Overall Presentation Goal

Learn an easy, quick and natural way to write robust and compact tests for

Java-based Rich GUIs: Swing and JavaFX

Page 3: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 4: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 5: Rich GUI Testing: Swing and JavaFX

Why GUI testing is difficult?

Ideally, tests must be automated, but GUIs are designed for humans

Conventional unit testing is not suitable for testing GUIs: GUI components are usually composed of more than one class

The room for potential interactions with a GUI is huge

Conventional test coverage is not enough to cover all user interaction scenarios

Page 6: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 7: Rich GUI Testing: Swing and JavaFX

Requirements for robust GUI testing

Being able to simulate user input Having a reliable mechanism for finding

GUI components Being able to tolerate changes in

Component position Component size Layout

Page 8: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 9: Rich GUI Testing: Swing and JavaFX

Writing testable GUIs

Keep the UI layer as thin as possible Use a unique name for GUI components Do not test default component behavior Concentrate on testing the expected

behavior of your GUI

Page 10: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 11: Rich GUI Testing: Swing and JavaFX

Top-3 must-have features in a GUI testing library Intuitive API for test creation Concise and easy-to-read API Ability to aid developers troubleshoot test

failures

Page 12: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 13: Rich GUI Testing: Swing and JavaFX

Introducing FEST

Supports functional Swing and JavaFX GUI testing

Website: http://fest.easytesting.org Its API provides a fluent interface Supports component lookup by name, by

type and by custom search criteria Open Source project (Apache 2.0 license) Supports both TestNG and JUnit Simplifies troubleshooting GUI test failures

Page 14: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 15: Rich GUI Testing: Swing and JavaFX

Our demo application: an RSS reader

Provides simple business logic Its user interface includes:

Complex GUI components like JTree and JTable Time-consuming tasks:

Database access Retrieval of web feeds from the Internet Drag ‘n drop

Page 16: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 17: Rich GUI Testing: Swing and JavaFX

Failures may be due to: Environmental conditions A GUI component could not be found More than one GUI component satisfied the given

search criteria Programming defect

Troubleshooting failures

Page 18: Rich GUI Testing: Swing and JavaFX

Failure due to environmental conditions Typical example: scheduled anti-virus software scan

starts in the middle of our test session A screenshot of the desktop at the moment of

failure can help us determine if an environmental condition was responsible for the failure

Troubleshooting failures

Page 19: Rich GUI Testing: Swing and JavaFX

Failure due to environmental conditions FEST can automatically embed a screenshot of the

desktop in a HTML test report (TestNG or JUnit)!

Troubleshooting failures

Page 20: Rich GUI Testing: Swing and JavaFX

Configuration is easy, short and reuses existing infrastructure

<testng listeners="org...ScreenshotOnFailureListener" outputDir="${target.test.results.dir}">

<classfileset dir="${target.test.classes.dir}" includes="**/*Test.class" /> <classpath location="${target.test.classes.dir}" /> <classpath location="${target.classes.dir}" /> <classpath refid="test.classpath" /> </testng>

Troubleshooting failures

Page 21: Rich GUI Testing: Swing and JavaFX

Failure due to GUI component not found For example, looking for a button with name “ok” in

a dialog that does not contain such button! Having access to the current component hierarchy

can help us figure out why a component could not be found

FEST includes the current component hierarchy when throwing a ComponentLookupException

Troubleshooting failures

Page 22: Rich GUI Testing: Swing and JavaFX

Unable to find component using matcher org.fest.swing.core.NameMatcher[name='label', requireShowing=false].

Troubleshooting failures

Page 23: Rich GUI Testing: Swing and JavaFX

Unable to find component using matcher org.fest.swing.core.NameMatcher[name='label', requireShowing=false].

Component hierarchy:org.fest.test.MainWindow[name='frame0',

title='BasicComponentFinderTest', enabled=true, visible=true, showing=true]

javax.swing.JRootPane[] javax.swing.JPanel[name='null.glassPane'] javax.swing.JPanel[name='null.contentPane'] javax.swing.JButton[name='button', text='A

Button', enabled=true, visible=true, showing=true]

Troubleshooting failures

Page 24: Rich GUI Testing: Swing and JavaFX

Failure due to more than one GUI component satisfies a lookup condition For example, looking up a button with name “ok” in

a dialog We have accidentally named two buttons with the

same name! Once again, FEST assists us by providing the list of

found components in the thrown ComponentLookupException

Troubleshooting failures

Page 25: Rich GUI Testing: Swing and JavaFX

Let’s image we have a JFrame with two JButtons

Our test tries to find a JButton by type and click it:

FrameFixture frame = new FrameFixture(new MyFrame());

frame.show();frame.button().click();

Troubleshooting failures

Page 26: Rich GUI Testing: Swing and JavaFX

Will throw the exception:

org.fest.swing.exception.ComponentLookupException: Found more than one component using matcher org.fest.swing.core.TypeMatcher[type=javax.swing.JButton, requireShowing=false].

Troubleshooting failures

Page 27: Rich GUI Testing: Swing and JavaFX

Will throw the exception:

org.fest.swing.exception.ComponentLookupException: Found more than one component using matcher org.fest.swing.core.TypeMatcher[type=javax.swing.JButton, requireShowing=false].

Found: javax.swing.JButton[name='first', text='First Button',

enabled=true] javax.swing.JButton[name='second', text='Second

Button', enabled=true]

Troubleshooting failures

Page 28: Rich GUI Testing: Swing and JavaFX

Agenda

Why testing GUIs is difficult? Requirements for robust GUI testing Writing testable GUIs Top-3 must-have features in a GUI testing

library Introducing FEST, an open source library for

GUI testing Coding Demos Troubleshooting GUI test failures Conclusion

Page 29: Rich GUI Testing: Swing and JavaFX

Wait!What about JavaFX?

Page 30: Rich GUI Testing: Swing and JavaFX

JavaFX 2.0: Java APIs

Java APIs means: TestNG/JUnit Code coverage tools (Cobertura, Clover) Code quality tools (FindBugs, Checkstyle)

Faster development of GUI functional testing tools

Page 31: Rich GUI Testing: Swing and JavaFX

Roadmap

We will continue supporting Swing testing Since Swing support is mature, we can

focus on JavaFX testing Release date? Unknown Please remember: we work on our own

spare time

Page 32: Rich GUI Testing: Swing and JavaFX

Conclusion

GUI testing is necessary for improving the quality of our applications

For GUIs, functional testing is more suitable than unit testing

Successful testing strategy: Create testable GUIs Write robust GUI tests Pick the right testing tool for your needs

(e.g. FEST) Happy testing!