Automated GUI testing How to test an interactive application automatically?

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

J-Unit Framework.
Testing Object Oriented Programs CSE 111 4/28/20151.
Unit 091 Introduction to GUI Programming Introduction to User Interfaces Introduction to GUI Programming GUI Design Issues GUI Programming Issues Java.
JUnit, Revisited 17-Apr-17.
Object-Oriented Analysis and Design
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
Unit Testing Discussion C. Unit Test ● public Method is smallest unit of code ● Input/output transformation ● Test if the method does what it claims ●
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Io package as Java’s basic I/O system continue’d.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Java Beans.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Welcome to CIS 083 ! Events CIS 068.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Capture and Replay Often used for regression test development –Tool used to capture interactions with the system under test. –Inputs must be captured;
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Designing Interface Components. Components Navigation components - the user uses these components to give instructions. Input – Components that are used.
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Chapter 9: Visual Programming Basics Object-Oriented Program Development Using Java: A Class-Centered Approach.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Automated GUI testing How to test an interactive application automatically?
DB2 Universal Database Confidential | July 2012 | India Software Lab Click to add text © 2012 IBM Corporation An End to End Windows Automation Framework.
3461 Model-View Controller Advanced GUI concepts.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
JUnit Dwight Deugo Nesa Matic
ESO - Garching 23 June – 02 July, 2003 ACS Course JUnit for Java Unit Testing H. Sommer.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
JUnit Dwight Deugo Nesa Matic
SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Slide 1 ACS Foundation Software Update Version 1.80.
Oct 021 Outline What is a widget? Buttons Combo boxes Text components Message boxes.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
Swinging in Your Java Playground. Background Swing is a part of the Java Foundation Classes (JFC). The JFC is made up of features intended to give a programmer.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Unit Testing with FlexUnit
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
1 JUnit. 2 Unit Testing with JUnit If code has no automated test case written for it to prove that it works, it must be assumed not to work. An API that.
Sep 181 Example Program DemoTranslateEnglishGUI.java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
CSC 222: Object-Oriented Programming
Support for the Development of Interactive Systems
CHAPTER Reacting to the user.
Java Look-and-Feel Design Guidelines
Lecture 27 Creating Custom GUIs
Gannon University Frank Xu
Introduction to Computing Using Java
Learning Outcome 2 – Assignment
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
Presentation transcript:

Automated GUI testing How to test an interactive application automatically?

2 Some GUI facts Software testing accounts for 50-60% of total software development costs GUIs can constitute as much as 60% of the code of an application GUI development frameworks such as Swing make GUI development easier Unfortunately, they make GUI testing much harder

3 Why is GUI testing difficult? Event-driven architecture User actions create events An automatic test suite has to simulate these events somehow Large space of possibilities The user may click on any pixel on the screen Even the simplest components have a large number of attributes and methods JButton has more than 50 attributes and 200 methods The state of the GUI is a combination of the states of all of its components

4 Challenges of GUI testing Test case generation: What combinations of user actions to try? Oracles: What is the expected GUI behaviour? Coverage: How much testing is enough? Regression testing: Can test cases from an earlier version be re-used? Representation: How to represent the GUI to handle all the above?

5 A GUI test case 1.Select text “Some” 2.Menu “Format” 3.Option “Font”

6 A GUI Test Case 4. Combobox “Size” 5. Click on Click OK

7 A GUI Test Case 7. Select “text” 8. Click U 9. Verify that the output looks like this

8 GUI vs. business model testing GUI testing The look of the text in the editor window corresponds to the operations performed The U button is selected All appropriate actions are still enabled, i.e. we can italicize the underlined text Business model testing Word’s internal model reflects the text formatting we performed

9 Two approaches to GUI testing 1. Black box Launch application Simulate mouse and keyboard events Compare final look to an existing screen dump Very brittle test cases Cannot test business model Framework independent

10 Two approaches to GUI testing 2. Glass box Launch application in the testing code Obtain references to the various components and send events to them Assert the state of components directly Test cases harder to break Business model can be tested Framework dependent

11 A first approach The Java API provides a class called java.awt.Robot It can be used to generate native system input events Different than creating Event objects and adding them to the AWT event queue These events will indeed move the mouse, click, etc.

12 RobotDemo

13 Testing with Robot User input can be simulated by the robot How to evaluate that the correct GUI behaviour has taken place? Robot includes method public BufferedImage createScreenCapture(Rectangle screenRe ct)BufferedImageRectangle Creates an image containing pixels read from the screen

14 Problems with this approach Low-level Would rather say “Select "blue" from the colour list” than Move to the colour list co-ordinates Click Press  5 times Click Brittle test cases (regression impossible)

15 A better approach Every GUI component should provide a public API which can be invoked in the same manner via a system user event or programmatically Component behaviour should be separated from event handling code For example, class JButton contains the doClick() method

16 Unfortunately… Most GUI development frameworks are not designed in this fashion In Swing, event handling is mixed with complex component behaviour in the Look and Feel code Few components offer methods such as doClick()

17 Abbot – A Better ’Bot A GUI testing framework for Swing Works seamlessly with Junit Uses some Junit 3 features Can be used to create Unit tests for GUI components Functional tests for existing GUI apps Open source

18 Goals of the Abbot framework Reliable reproduction of user input High-level semantic actions Scripted control of actions Loose component bindings

19 Abbot overview A better Robot class is provided abbot.tester.Robot includes events to click, drag, type on any component For each Swing widget a corresponding Tester class is provided E.g. JPopupMenuTester provides a method called getMenuLabels() Components can be retrieved from the component hierarchy No direct reference to any widget is necessary

20 A typical test case JButton button = (JButton)getFinder().find( new Matcher() { public boolean matches(Component c) { return c instanceof JButton && ((JButton)c).getText().equals("OK"); }}); AbstractButtonTester tester = new AbstractButtonTester(); Tester.actionClick(button); assertEquals("Wrong button tooltip", "Click to accept", button.getToolTipText());

21 Testing with Abbot demo

22 JUnit 3 features Abbot requires JUnit 3 Only the differences between JUnit 3 and JUnit 4 are presented in the next slides The JUnit 3 jar file is included in the abbot distribution

23 Extending TestCase Each test class needs to extend class junit.framework.TestCase public class SomeClassTest extends junit.framework.TestCase { … }

24 Naming vs. Annotations protected void setUp() method must have this signature protected void tearDown() method must have this signature public void testAdd() public void testToString() methods must have names that start with test Do not include any annotations

25 Test suite creation Creating a test suite with JUnit 3 is also different Use the code in the next slide as a template

import junit.framework.*; public class AllTests { public static void main(String[] args) { junit.swingui.TestRunner.run(AllTests.class); } public static Test suite() { TestSuite suite = new TestSuite(”Name"); suite.addTestSuite(TestClass1.class); suite.addTestSuite(TestClass2.class); return suite; }