Automated GUI Testing How to test an interactive application - - PowerPoint PPT Presentation

automated gui testing how to test an interactive
SMART_READER_LITE
LIVE PREVIEW

Automated GUI Testing How to test an interactive application - - PowerPoint PPT Presentation

Automated GUI Testing How to test an interactive application automatically Some GUI facts Software testing accounts for 50-60% of total software development costs AGUI2 Some GUI facts 2 Software testing accounts for 50-60% of total


slide-1
SLIDE 1

Automated GUI Testing How to test an interactive application automatically

slide-2
SLIDE 2

AGUI–2

Some GUI facts

 Software testing accounts for 50-60% of total software

development costs

slide-3
SLIDE 3

AGUI–3

Some GUI facts – 2

Software testing accounts for 50-60% of total software development costs

 GUIs can constitute as much as 60% of the code of an

application

slide-4
SLIDE 4

AGUI–4

Some GUI facts – 3

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

slide-5
SLIDE 5

AGUI–5

Some GUI facts – 4

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 more difficult

slide-6
SLIDE 6

AGUI–6

Why is GUI testing difficult?

 Why is GUI testing so difficult?

slide-7
SLIDE 7

AGUI–7

Why is GUI testing difficult? – 2

 Why is GUI testing so difficult?

 Event-driven architecture

 User actions create events  An automatic test suite has to simulate these

events somehow

slide-8
SLIDE 8

AGUI–8

Why is GUI testing difficult? – 3

 Why is GUI testing so difficult?

 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

  • f all of its components
slide-9
SLIDE 9

AGUI–9

Challenges of GUI testing

 Test case generation

 What combinations of user actions to try?

slide-10
SLIDE 10

AGUI–10

Challenges of GUI testing – 2

Test case generation

 What combinations of user actions to try?

 Oracles

 What is the expected GUI behaviour?

slide-11
SLIDE 11

AGUI–11

Challenges of GUI testing – 3

Test case generation

 What combinations of user actions to try?

Oracles

 What is the expected GUI behaviour?

 Coverage

 How much testing is enough?

slide-12
SLIDE 12

AGUI–12

Challenges of GUI testing – 4

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?

slide-13
SLIDE 13

AGUI–13

Challenges of GUI testing – 5

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?

slide-14
SLIDE 14

AGUI–14

A GUI test case

  • 1. Select text “Some”
  • 2. Menu “Format”
  • 3. Option “Font”
slide-15
SLIDE 15

AGUI–15

A GUI test case

  • 4. Combobox “Size”
  • 5. Click on 26
  • 6. Click OK
slide-16
SLIDE 16

AGUI–16

A GUI test case

  • 7. Select “text”
  • 8. Click U
  • 9. Verify that the
  • utput looks

like this

slide-17
SLIDE 17

AGUI–17

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

slide-18
SLIDE 18

AGUI–18

GUI vs. business model testing – 2

 Business model testing

 Wordʼs internal model reflects the text formatting we

performed

slide-19
SLIDE 19

AGUI–19

Two approaches to GUI testing

 Why is GUI testing so difficult?

slide-20
SLIDE 20

AGUI–20

Two approaches to GUI testing – 2

 Why is GUI testing so difficult?

 Black Box  Glass Box

slide-21
SLIDE 21

AGUI–21

Black box GUI testing

 How do we do black box testing?

slide-22
SLIDE 22

AGUI–22

Black box GUI testing – 2

How do we do black box testing?

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

slide-23
SLIDE 23

AGUI–23

Glass box GUI testing

 How do we do glass box testing?

slide-24
SLIDE 24

AGUI–24

Glass box GUI testing – 2

How do we do glass box testing?

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 more difficult to break

Business model can be tested

Framework dependent

slide-25
SLIDE 25

AGUI–25

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.

slide-26
SLIDE 26

AGUI–26

RobotDemo

slide-27
SLIDE 27

AGUI–27

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 screenRect )

 Creates an image containing pixels read from the

screen

slide-28
SLIDE 28

AGUI–28

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)

slide-29
SLIDE 29

AGUI–29

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

 Principle of reciprocity

slide-30
SLIDE 30

AGUI–30

A better approach – 2

Every GUI component should provide a public API which can be invoked in the same manner via a system user event or programmatically

 Principle of reciprocity

 Component behaviour should be separated from event

handling code

slide-31
SLIDE 31

AGUI–31

A better approach – 3

Every GUI component should provide a public API which can be invoked in the same manner via a system user event or programmatically

 Principle of reciprocity

Component behaviour should be separated from event handling code

 For example, class JButton contains the doClick()

method

slide-32
SLIDE 32

AGUI–32

Unfortunately…

 Most GUI development frameworks are not designed in

this fashion

slide-33
SLIDE 33

AGUI–33

Unfortunately… – 2

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

slide-34
SLIDE 34

AGUI–34

Unfortunately… – 3

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()

slide-35
SLIDE 35

AGUI–35

Abbot – A Better ʼBot

 A GUI testing framework for Swing

slide-36
SLIDE 36

AGUI–36

Abbot – A Better ʼBot – 2

A GUI testing framework for Swing

 Works seamlessly with Junit

 Uses some Junit 3 features

slide-37
SLIDE 37

AGUI–37

Abbot – A Better ʼBot – 3

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

slide-38
SLIDE 38

AGUI–38

Abbot – A Better ʼBot – 4

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

 http://abbot.sourceforge.net/

slide-39
SLIDE 39

AGUI–39

Goals of the Abbot framework

 Reliable reproduction of user input

slide-40
SLIDE 40

AGUI–40

Goals of the Abbot framework – 2

Reliable reproduction of user input

 High-level semantic actions

slide-41
SLIDE 41

AGUI–41

Goals of the Abbot framework – 3

Reliable reproduction of user input

High-level semantic actions

 Scripted control of actions

slide-42
SLIDE 42

AGUI–42

Goals of the Abbot framework – 4

Reliable reproduction of user input

High-level semantic actions

Scripted control of actions

 Loose component bindings

slide-43
SLIDE 43

AGUI–43

Abbot overview

 A better Robot class is provided

 abbot.tester.Robot includes events to click, drag, type

  • n any component
slide-44
SLIDE 44

AGUI–44

Abbot overview – 2

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()

slide-45
SLIDE 45

AGUI–45

Abbot overview – 3

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

slide-46
SLIDE 46

AGUI–46

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());

slide-47
SLIDE 47

AGUI–47

Testing with Abbot demo

slide-48
SLIDE 48

AGUI–48

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

slide-49
SLIDE 49

AGUI–49

Extending TestCase

 Each test class needs to extend class

junit.framework.TestCase public class SomeClassTest extends junit.framework.TestCase { … }

slide-50
SLIDE 50

AGUI–50

Naming vs. Annotations

 protected void setUp()

 The @Before method must have this signature

 protected void tearDown()

 The @After method must have this signature

 public void testAdd()

public void testToString()

 All @Test methods must have names that start with

test

 Do not include any annotations

slide-51
SLIDE 51

AGUI–51

Test suite creation

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

slide-52
SLIDE 52

AGUI–52

Test suite creation 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; } }