Simplifying Development and Testing of GUIs with SAF (JSR 296) and FEST. Michael Hüttermann Training & Consulting Alex Ruiz Oracle Corporation

Similar documents
Using NetBeans IDE for Desktop Development. Geertjan Wielenga

Java Swing Introduction

JSR 377 Desktop Application Framework September Andres Almiray

Graphical User Interfaces (GUIs)

Unit testing basics & more...

Oracle Fusion Middleware 11g: Build Applications with ADF I

JSR377 What's up and what's next. Andres Almiray Canoo Engineering AG

Improve and Expand JavaServer Faces Technology with JBoss Seam

EPITA Première Année Cycle Ingénieur. Atelier Java - J5

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Swinging from the Outside

Java: Graphical User Interfaces (GUI)

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Oracle Fusion Middleware 11g: Build Applications with ADF I

Active Endpoints. ActiveVOS Platform Architecture Active Endpoints

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Jonathan Aldrich Charlie Garrod

OSGi on the Server. Martin Lippert (it-agile GmbH)

CHAPTER 1: A GENERAL INTRODUCTION TO PROGRAMMING 1

Properties of High Quality Software. CSE219, Computer Science III Stony Brook University

CSE wi Final Exam 3/12/18 Sample Solution

JAVA SYLLABUS FOR 6 MONTHS

Junit Overview. By Ana I. Duncan

Oracle Fusion Middleware 11g: Build Applications with ADF Accel

Mobile Development Workshop DAY 2: INTRODUCTION TO JAVA

Testing with Soap UI. Tomaš Maconko

Agenda Time (PT) 8:45 a.m. Event Platform Opening 9:00 a.m. Keynote - Java: Present and Future Java EE 7 Java SE 8 Java Embedded

CSE wi Final Exam 3/12/18. Name UW ID#

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Netbeans Platform For Beginners

Introduction to the JAVA UI classes Advanced HCI IAT351

In this lab we will practice creating, throwing and handling exceptions.

Turning a Marathon Runner into a Sprinter: Adopting Agile Testing Strategies and Practices at Microsoft

J2EE Application Development : Conversion and Beyond Osmond Ng

Enterprise Java TM Web Apps with Google Open Source Technology

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

(Incomplete) History of GUIs

Tooling for Ajax-Based Development. Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

THIS IS ONLY SAMPLE RESUME - DO NOT COPY AND PASTE INTO YOUR RESUME. WE ARE NOT RESPONSIBLE Name: xxxxxx

Enterprise Java Development using JPA, Hibernate and Spring. Srini Penchikala Detroit JUG Developer Day Conference November 14, 2009

The Eclipse Rich Ajax Platform

Rational Functional Tester - Tips and Tricks

Software Engineering I (02161)

JVA-117A. Spring-MVC Web Applications

CS Exam 1 Review Suggestions

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Graphical User Interface (GUI)

Web Application Development Using Spring, Hibernate and JPA

Java. GUI building with the AWT

Automated GUI testing. How to test an interactive application automatically?

AN ISO 9001:2008 CERTIFIED COMPANY. Software Testing TRAINING.

The Power of Unit Testing and it s impact on your business. Ashish Kumar Vice President, Engineering

Petr Suchomel Architect, NetBeans Mobility

Gradle Leveraging Groovy for Building Java Applications. Hans Dockter Gradle Project Lead

Oracle Developer Day

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Mobile Application Development. Introduction. Dr. Christelle Scharff Pace University, USA

<Insert Picture Here> JavaFX 2.0

How we reached 0 technical debt in our Eclipse project

Building Web Applications With The Struts Framework

Introduction to concurrency and GUIs

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

[module lab 2.2] GUI FRAMEWORKS & CONCURRENCY

Oracle Developer Day

DESIGN PATTERN - INTERVIEW QUESTIONS

Continuous Testing in Eclipse. David Saff, Michael D. Ernst MIT CSAIL etx 2004, Barcelona, Spain

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

CS 209 Programming in Java #10 Exception Handling

Oracle Middleware 12c: Build Rich Client Applications with ADF Ed 1 LVC

GUI Output. Adapted from slides by Michelle Strout with some slides from Rick Mercer. CSc 210

GUI Testing to the edge. Quality is not a given and testing is fun

Eclipse + Html: A Journey

1. What is Jav a? simple

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

Groovy & Grails Scripting for Modern Web Applications. Rohit Nayak Talentica Software

Wednesday, January 25, 12

Web Application Development Using Spring, Hibernate and JPA

Principles of Software Construction: Testing: One, Two, Three

Patterns and Best Practices for dynamic OSGi Applications

Graphic User Interfaces. - GUI concepts - Swing - AWT

Introduction to Java

WHITESTEIN. Agents in a J2EE World. Technologies. Stefan Brantschen. All rights reserved.

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

VizzAnalyzer goes Eclipse!

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Automated Acceptance Testing

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Strategies for Loose Coupling in Large Java Desktop Applications

CS11 Advanced Java. Winter Lecture 2

JBuilder 2007 Product Tour November 2006

Java FX. Threads, Workers and Tasks

Eclipse Lyo Overview. Michael Fiedler, Eclipse Lyo committer IBM Corporation

For detailed technical instructions refer to the documentation provided inside the SDK and updated samples.

Java EE 6: Develop Web Applications with JSF

Marthon User Guide. Page 1 Copyright The Marathon developers. All rights reserved.

QMS ISO 9001:2015 CERTIFIED COMPANY Software Testing TRAINING.

Software Engineering Design & Construction

Transcription:

Simplifying Development and Testing of GUIs with SAF (JSR 296) and FEST Michael Hüttermann Training & Consulting Alex Ruiz Oracle Corporation

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

About us Alex Ruiz Senior Engineer at Oracle Founder and major contributor of FEST Father ;-) Michael Hüttermann Self-employed consultant on Java TM /JEE, SCM/ALM, SDLC tooling and agile development Speaker at conferences, author of books and articles Stage producer of Agile 2009's Tools for Agility track

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Why do we need a Swing framework? Swing: powerful but difficult Swing has been available for many years It is very powerful and very complex Too easy to do things wrong and get away with it Too many possible paths: scares beginners Developers should focus on the application domain, not on the architecture Need a standard way to develop Swing UIs All bigger projects do write an own framework

Why do we need a Swing framework? Swing is too difficult for beginners Easy to adopt bad practices: application is a JFrame Internationalization Performance Organization of event listeners Much boiler plate code Development is error prone Patterns and architecture do matter!

Why do we need a Swing framework? Even experienced developers can get it wrong The most common: violations of Event Dispatch Thread (EDT) access Incorrect division of responsibilities: classes that perform logic are event listeners at the same time Pretty long kick-off time, not "straight ahead" Why only web frameworks? Many more!

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Introducing the Swing Application Framework (SAF) Provides a simple application framework for Swing applications Not intended to cover all needs of applications JSR 296 Reference implementation in java.net To be included in Java 7 (or not?) Not intended to compete with Netbeans RCP or Eclipse RCP Easy to learn: no more than a day

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

SAF Features Application Lifecycle and common services Defines application lifecycle: startup, shutdown, etc. EDT-safe: o Application constructed in EDT o Application started in EDT Startup progress reported by standard milestones UI component (event) handling Basic session persistance Threading

SAF Features Application is not a JFrame anymore Developers only need to extend Application or a subclass, and override appropriate lifecycle methods: class MyApp extends Application { protected void startup(string[] args) { JFrame frame = new JFrame("My App"); frame.add(new JLabel("Hello World!")); frame.pack(); frame.setvisible(true); } public static void main(string[] args) { Application.launch(MyApp.class, args); } }

SAF Features Application is not a JFrame anymore Extend SingleFrameApplication for an application with a primary JFrame: class MyApp extends SingleFrameApplication { protected void startup(string[] args) { JPanel panel = new JPanel(new BorderLayout()); panel.add(acomponent, BorderLayout.NORTH); show(panel); } public static void main(string[] args) { Application.launch(MyApp.class, args); } }

SAF Features Component Resource Injection Set component properties whose names match a resource name Inject just one component, or all components in a hierarchy Resource names must match: component.getname() +.propertyname Converts Strings to correct type (e.g. icon) Uses good old ResourceBundle (*.properties files)

SAF Features Field Resource Injection Icon valued fields initialized from a ResourceMap: public class Form extends JPanel { @Resource Icon busyicon; @Resource Icon readyicon; void showstatus(boolean busy) { mylabel.seticon(busy? busyicon : readyicon); } Form() { Application app = Application.getInstance(); ResourceMap r = app.getcontext().getresourcemap(form.class); r.injectfields(this); } } ResourceBundle properties File: # resources/form.properties ResourceBundle Form.busyIcon = busy-icon.png Form.readyIcon = ready-icon.png

SAF Features Actions Plain old Swing world: o Actions implement Action or extend AbstractAction o Semantics: actionperformed(), enabled, selected o ActionMap maps names to actions

SAF Features Actions (II) With SAF: o Actions are simply annotated with @Action, one per actionperformed o They can also be asynchronous or block facets o One class can define many actions class MyActions { @Action void newfile() {... } @Action void fileopened(actionevent e) {... } }

SAF Features Actions (III) Asynchronous actions return a Task @Action Task<?,?> savefile() { return new MyTask(); } Task extends SwingWorker Overwrite methods like doinbackground()

SAF Features Actions (IV) Blocking actions have five scopes: NONE, ACTION, WINDOW, COMPONENT, APPLICATION @Action(block=BlockingScope.APPLICATION) Blocks the facet Provides basic functionality like blocking dialogs

SAF Features Action Maps Create an Action for each @Action: ActionMap amap = getcontext().getactionmap() cutbutton.setaction(amap.get("cut")); copybutton.setaction(amap.get("copy")); Action attributes come from a ResourceMap: # resources/myactions.properties ResourceBundle cut.action.text = Cut cut.action.accelerator = control U cut.action.shortdescription = Cut to clipboard copy.action.text = Copy copy.action.acceleratorkey = control C copy.action.shortdescription = Copies to clipboard

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Status of SAF JSR 296 marked as inactive Original project lead left Sun Project revived under new lead: Alexander Potochkin Project resumed activity, call for contribution Further direction not clear in all facets What should be content of SAF? Legacy apps vs. greenfield projects SAF to be included in Java 7 SAF probably not included in Java 7

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Testing Swing UIs Why? During development: o Testing GUIs can make the entire system safer and more robust o Tests to specify the functionality o Test early > better design During acceptance testing (specify features) and integration/system testing During maintenance: o Code might be refactored frequently to improve design, and this code often encloses great portions of the user interface. o Having a solid test suite that includes GUI code can give us confidence that we are not inadvertently introducing bugs.

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Why UI testing is hard Conventional unit testing is not suitable for testing UIs: UI components are usually composed of more than one class The room for potential interactions with a UI is huge Conventional test coverage is not enough to cover all user interaction scenarios Addressing and driving the controls Test isolation and reuse of tests CR is not enough

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Writing testable GUIs Separate Model and View Use a unique name for GUI components Do not test default component behavior Concentrate on testing the expected behavior of your GUI Test isolation Mocking Do not only use CR-Tools!

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Introducing FEST Open Source Library for UI Testing Supports functional Swing UI testing Website: http://fest.easytesting.org Its API provides a fluent interface Open Source project (Apache 2.0 license) Supports both TestNG and JUnit Simplifies troubleshooting UI test failures Hosted at CodeHaus

Introducing FEST Robust UI testing Simulates user input using native UI events Provides a reliable mechanism for finding GUI components Tolerates changes in o Component position o Component size o Layout

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

FEST Features Fluent Interface Compact, intuitive and readable API Makes it easy to write and maintain UI tests dialog.combobox("domain").select("users"); dialog.textbox("name").entertext("leia"); dialog.button("login").click(); dialog.optionpane().requireerrormessage();

FEST Features Reliable Component Lookup By default, uses component names to look up UI components dialog.button("ok").click(); It can also use component types and custom search criteria (e.g. testing legacy applications) GenericTypeMatcher<JButton> textmatcher = new GenericTypeMatcher<JButton>() { protected boolean ismatching(jbutton button) { return "OK".equals(button.getText()); } }; dialog.button(textmatcher).click();

FEST Features Test Violations of EDT Access EDT access violation is a common bad practice, even for experienced Swing developers FEST can verify that EDT access is correct Simply install: FailOnThreadViolationRepaintManager.install();

FEST Features Troubleshooting UI test failures Failures may be due to: o Environmental conditions o A GUI component could not be found o More than one GUI component satisfied the given search criteria o Programming defect

FEST Features Troubleshooting UI test failures (II) Failure due to environmental conditions o Typical example: scheduled anti-virus software scan starts in the middle of our test session o A screenshot of the desktop at the moment of failure can help us determine if an environmental condition was responsible for the failure

FEST Features Troubleshooting UI test failures (III) Failure due to environmental conditions o FEST can automatically embed a screenshot of the desktop in a HTML test report (TestNG or JUnit)! o Configuration is easy, short and reuses existing infrastructure

FEST Features Troubleshooting UI test failures (IV) Failure due to GUI component not found o For example, looking for a button with name ok in a dialog that does not contain such button! o Having access to the current component hierarchy can help us figure out why a component could not be found o FEST includes the current component hierarchy when throwing a ComponentLookupException

FEST Features Troubleshooting UI test failures (V) Failure due to more than one GUI component satisfies a lookup condition o For example, looking up a button with name ok in a dialog o We have accidentally named two buttons with the same name! o Once again, FEST assists us by providing the list of found components in the thrown ComponentLookupException

FEST Features JavaFX Support public void shouldupdatetextboxwithpressednumber() { calculator.swingbutton(withtext("8")).click(); calculator.textbox().requiretext("8"); calculator.swingbutton(withtext("6")).click(); calculator.textbox().requiretext("86"); } Work in progress

FEST Features Fluent Assertions String[] newhires = employees.newhiresnames(); assertthat(newhires).containsonly("r2-d2"); assertthat(yoda).isinstanceof(jedi.class).isequalto(foundjedi).isnotequalto(foundsith);

FEST Features DSL for Java Reflection // Regular Java Reflection: Method method = Names.class.getMethod("get", int.class); AccessController.doPrivileged( new PrivilegedAction<Void>() { public Void run() { method.setaccessible(true); return null; } }); String name = (String) method.invoke(names, 8); // FEST-Reflection: String name = method("get").withreturntype(string.class).withparametertypes(int.class).in(names).invoke(8);

FEST Features Template for EasyMock @Test public void shouldupdateemployee() { new EasyMockTemplate(mockEmployeeDao) { protected void expectations() { mockemployeedao.update(employee); } protected void codetotest() { employeebo.updateemployee(employee); } }.run(); }

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

FEST Roadmap Provide support for 3rd party Swing libraries: o Flamingo Component Suite o JIDE o SwingX Groovy-based DSL Support for JavaFX (in the works) Much more!

Agenda Why do we need a Swing framework? Introducing the Swing Application Framework (SAF) SAF Features Status of SAF Testing Swing UIs Why UI testing is hard Writing testable UIs Introducing FEST FEST Features FEST Roadmap

Summary Swing is a very powerful UI toolkit With power comes complexity SAF can simplify creation of Swing UIs SAF is a lean application framework Creation is only the beginning, we need to test UI testing is necessary for improving the quality of our applications FEST provides a tool that makes creation and maintenance of UI tests a breeze Test your UIs!

Michael Hüttermann michael@huettermann.net Alex Ruiz alex.ruiz.05@gmail.com