Top Banner
AUTOMATING INTERACTION TESTING AGILE PORTUGAL 2010 1 INTERACTION TESTING WITH UML SEQUENCE DIAGRAMS: WHERE TDD AND UML MEET João Pascoal Faria ([email protected]) 25 July 2010
20

Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

May 11, 2015

Download

Technology

João Faria
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

AUTOMATING INTERACTION TESTING

AGILE PORTUGAL 2010

1

INTERACTION TESTING WITH UML SEQUENCE DIAGRAMS: WHERE TDD AND UML MEETJoão Pascoal Faria ([email protected])25 July 2010

Page 2: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

The problem

� The development of computer-based UML (OO) design models used as documentation only � is time consuming

� the result is often wrong

2

� the result soon becomes outdated

� This is a concern both for� Educators/students: effective teaching/learning OOD

� Professionals: cost-effective & agile development of high-quality software

Page 3: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Possible solutions

� Not using UML

� Paper/hand drawings� Fast, but difficult to verify and maintain� Good for initial thinking

3

� Reverse engineering (from code to models)� Fast, ensures consistency, difficult to abstract details away� May be good for documenting but not doing the design

� Automatic code/test generation from models (MDD/MBT)

� Time invested can be recovered� The quality of the models can be checked and improved� There is a good chance that they are kept up-to-date

All 3 important, can be used in combination, focus here on the last one

Page 4: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

What UML diagrams? (1/2)

� Focus here is in detailed/OOD (classes)� Not architectural design (components, etc.)

� Structure/syntax: class diagrams

4

� Structure/syntax: class diagrams� Generation of compile-ready class skeletons

supported by most UML tools

� A limited but successful form of MDD

Page 5: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

What UML diagrams? (2/2)

� Behavior/semantics: sequence diagrams first� Captures the essence of object behavior: message

exchange among objects� Nice fit for iterative dev. of use cases/scenarios/user stories� Simple completeness/done/consistency criteria wrt class

5

� Simple completeness/done/consistency criteria wrt class diagrams: using all classes and public methods

� Good for specifying gray-box tests (unit & interaction): instead of full heavy-weight behavior spec, partial light-weight behavior spec through test specs

� Need tools for generating test code (e.g., xUnit) from sequence diagrams� Check that interactions among objects occur as specified� A limited but viable form of MBT

Page 6: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

The proposed solution

UML ClassDiagrams

Enterprise Architect(EA) code generator Java Classes

(compile ready, empty methods)

Java Libraries

Complete method bodies (code)4

Uses

6

UML SequenceDiagrams

Diagrams

Add-in for EATest generator

New

empty methods)

JUnit testsTrace

Utilities(AspectJ)

New

Libraries

Traces executionof methods & constructors

Uses

Tests

Test results

1

1

2

2

53

design6 refactor

7 iterate

Page 7: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Enterprise Architect Add-In

� COM+ component developed in C#

� Interacts with EA through its Object-Model (gives access to the model elements)

7

access to the model elements)

� Generates JUnit source files from sequence diagrams (test specs)

� User only has to choose destination directory

Page 8: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Test organization

package spreadheettest;

import junit.framework.TestCase;

public class SpreadsheetAppTest extends TestCase {public void testCalculatedField() {…}

}

8

}

package spreadheettest;

import junit.framework.TestCase;

public class SpreadshhetTest extends TestCase {public void testCalculatedField() {…}public void testCircularReference() {.}

}

Each sequence diagram generates one test methodTest classes & packages generated according to hierarchical model organization.

Page 9: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Simple API black-box testing

� Constructor callpublic void testCalculatedField() {

Spreadsheet s0 = new Spreadsheet("s0");

9

� Method call and return

assertEquals("s0", s0.getName());

…}

Page 10: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Checking internal interactions10

…Trace.start();Cell x = new Cell("x", s0);Trace.check(

new Call("Spreadsheet", s0, "addCell", new Object[] {x}, null, null));…

expected internal call(s)

target class

methodtarget object

parameters return value

nested calls

Page 11: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Internal object creation & checking11

return parameters creation

Page 12: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Internal object creation & checking

…ObjectHandler r = new ObjectHandler();ObjectHandler c = new ObjectHandler();

Stores a reference to the actual object (initially null), which is assigned onfirst checking, and compared/tested on subsequent ones (by Trace.check).

12

ObjectHandler c = new ObjectHandler();ObjectHandler a = new ObjectHandler();Trace.start();y.setFormula("x + 1");Trace.check(

new Call("Parser", null, "parse", new Object[] {s0, "x + 1"}, a, new Call[] {new Call("CellReference", r, "CellReference", new Object[] {x}, null, null), new Call("Constant", c, "Constant", new Object[] {1.0}, null, null), new Call("Add", a, "Add", new Object[] {r, c}, null, null)}));

check parametersas internal objects

check return ofinternal object

check call oninternal object

Page 13: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Call tree checking

� The actual call tree must be a super-tree of the specified/expected call tree

� Violations checked: absence of call, bad parameters, bat target object, bad return values

13

� Intermmediate method calls (for example auxiliary methods) are allowed

� Allows focusing the specification on the relevant interactions (need not be a fully heavy-weight) specification

Page 14: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Exceptions14

try {x.getValue();fail(“Should have thrown CircularReferenceException");

}catch(CircularReferenceException exception) {}

Page 15: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

User

spreadsheetengine::SpreadsheetApp

s :Spreadsheetstart()

Spreadsheet("s")

enter("x = 1")

User Interaction - Modeling

With “main”, provides a simple command line interface

start (application) and enter (data) are keywords that represent user actions

15

x :CellCell("x", s)

setFormula("1")

enter("x + 1")getValue()

1.0()"2.0"()

enter("")

represent user actions

system displays information to the user

Illusion of user in control: user action/system response

User and system run concurrently User interaction Internal interactions

Page 16: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

User Interaction – Test generation

public void testCommandLineInterface {Console.start();

Thread thread1 = new Thread() {public void run() {

SpreadsheetApp.main(null);}

};

(Internal interaction checking ommited for simplification reasons)

starts console simulator

start()

enter("x = 1")

16

};thread1.start();

Console.enter("x = 1");

Console.enter("x + 1");

assertEquals("2.0", Console.check());

Console.enter("");

thread1.join(1000);assertFalse(thread1.isAlive());Console.stop();

}

enter("x = 1")

enter("x + 1")

"2.0"()

enter("")

wait for system termination

finishes console simulator

Page 17: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

User Interaction Testing – Console Simulator� “around” advice redefines console I/O behavior

� Currently only output via java.io.PrintStream

� Currently only input via java.util.Scanner

� Two Java LinkedBlockingQueue’s are used for

17

� Two Java LinkedBlockingQueue’s are used for communication data between system and test code� “around” advice redirects input/output calls to these queues

� Handles synchronization (blocking until data is available)

� Handles timeouts (maximum wait time)

� Application is developed normaly

Page 18: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Conclusions

� Approach supports lightweight behavior spec through sequence diagrams as test specs

� Test code is automatically generated fromsequence diagrams

18

sequence diagrams� Supports effective combination of agile

modeling and TDD (test-driven development)� Quality of models is tested

Page 19: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

Future Work

� Better fault localization and messages

� Multiple system behaviors allowed

� Improving user interaction testing

19

� Distributed and concurrent systems

� Multiple programming languages

� Circumvent some Enterprise Architect limitations

Page 20: Automating Interaction Testing with UML Sequence Diagrams: Where TDD and UML meet

ThankThankYou