unit testing

15
http://s- lab.upb.de Towards Model-Driven Unit Testing Gregor Engels Baris Güldali Marc Lohmann 02. October 2006 3rd Workshop on Model design and Validation @ MoDELS 2006

Upload: svein

Post on 11-Jan-2016

27 views

Category:

Documents


0 download

DESCRIPTION

Towards Model-Driven Unit Testing Gregor Engels Baris Güldali Marc Lohmann 02. October 2006 3rd Workshop on Model design and Validation @ MoDELS 2006. Unit Testing. Model-driven Unit Testing. 1. Models. 3. 2. generate. generate. 4. Test Case Input. Expected Output. Test Oracle. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unit Testing

http://s-lab.upb.de

TowardsModel-Driven Unit

Testing

Gregor EngelsBaris Güldali

Marc Lohmann

02. October 2006

3rd Workshop on Model design and Validation @ MoDELS 2006

Page 2: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Model-driven Unit TestingUnit Testing

Test Cases OperationComparat

orTest Case Input Actual Result

Expected Output

Pass/No Pass

Test Oracle

Test Case Input

Models

generate generate

1

23

4

Page 3: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Implementation

Design modelmodels

compile

Operation

Test Oracle + Comparator

completes

generate

Executable Binary Code

Visual Contracts

Java Class skeletons

Class Diagram

generate

AssertionsComplete, executable

applicationProgrammer

Designer

Development Process

Page 4: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

1 +cartItem

0..*

cartCreate() : CartcartAdd(Zoll cartId : String, Zoll ASIN : String, Zoll quantity : Integer) : String

«control»OnlineShop

cartId

1

0..*

3 controls

«key» cartId : String

«entity»Cart

«key» cartItemId : StringproductNo : Stringquantity : Integer

«entity»CartItem

«key» productNo : Stringtitle : String

«entity»Product

productNo

1

0..*

controls4

+cartItem

0..*

+product

1

...

cartCreate() : CartcartAdd(cartId : String, productNo : String, quantity : Integer) : String

«control»/self : OnlineShop

«control»/self : OnlineShop

«key» cartId = cid

«entity»/c : Cart

«key» cartId = cid

«entity»/c : Cart

«key» cartItemId = cartitemidproductNo = prNoquantity = num

«entity»/citem : CartItem

«key» productNo = prNotitle

«entity»/pr : Product

«key» productNo = prNotitle

«entity»/pr : Product

vc cartAdd(cid, prNo, num):cartitemid

UML Class Diagrams & Visual Contracts

Page 5: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Model-driven Unit Testing

Test CasesOperation under Test

Comparator

Test Case Input Actual Result

Expected Output

Pass/No Pass

Test Oracle

Test Case Input

Models

generate generate

1

23

4

Page 6: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

call operation under test

execute originaloperation with call parameters

Test Oracle

Test driver SUT

check pre-condition

check post-condition

throw pre-condition exception

throw post-condition exception

return normally

[pre-condition holds]

[post-condition holds]

[else]

[else]

system

state sk

system

state sk+1

alt return

exception

implemented by

created by

created by

Programmer

Designer

Pass

No Pass

Page 7: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Model-driven Unit Testing

Test CasesOperation under Test

Comparator

Test Case Input Actual Result

Expected Output

Pass/No Pass

Test Oracle

Test Case Input

Models

generate generate

1

23

4

1. Which test cases are adequate for testing a system wrt. a testing criterion?

2. How can a SUT be set to a state where the test cases can be executed?

Page 8: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

«control»/self : OnlineShop

«key» cartId = cid

«entity»/c : Cart

«key» productNo = prNotitle

«entity»/pr : Product

Test case inputs: call parameters + system state

1. Generation of call parametersP = {cid=„abc“, prNo=„def“, num=1}

2. Generation of system state

«control»/self : OnlineShop

«control»/self : OnlineShop

«key» cartId = cid

«entity»/c : Cart

«key» cartId = cid

«entity»/c : Cart

«key» cartItemId = cartitemidproductNo = prNoquantity = num

«entity»/citem : CartItem

«key» productNo = prNotitle

«entity»/pr : Product

«key» productNo = prNotitle

«entity»/pr : Product

vc cartAdd(cid, prNo, num):cartitemid

«control»/self : OnlineShop

«key» cartId = abc

«entity»/c : Cart

«key» productNo = deftitle

«entity»/pr : Product

Test Case Generation

Well-known test case generation techniques or random generation

sinput=

Page 9: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

1 +cartItem

0..*

cartCreate() : CartcartAdd(Zoll cartId : String, Zoll ASIN : String, Zoll quantity : Integer) : String

«control»OnlineShop

cartId

1

0..*

3 controls

«key» cartId : String

«entity»Cart

«key» cartItemId : StringproductNo : Stringquantity : Integer

«entity»CartItem

«key» productNo : Stringtitle : String

«entity»Product

productNo

1

0..*

controls4

+cartItem

0..*

+product

1

...

cartCreate() : CartcartAdd(cartId : String, productNo : String, quantity : Integer) : String

Setting System State

…«control»

/self : OnlineShop«control»

/self : OnlineShop

«key» cartId = cid

«entity»/c : Cart

«key» cartId = cid

«entity»/c : Cart

«key» cartItemId = cartitemidproductNo = prNoquantity = num

«entity»/citem : CartItem

«key» productNo = prNotitle

«entity»/pr : Product

«key» productNo = prNotitle

«entity»/pr : Product

vc cartAdd(cid, prNo, num):cartitemid

Page 10: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Setting System State3. Generation of system setting sequence

sv ⊇ sinput

s0

s1 s2

st su

sv

…… …

… …

cartCreate

operationn

«control»/self : OnlineShop

«entity»/c : Cart

«control»/self : OnlineShop

Model checking techniques for computation of thesystem setting sequence:cartCreate, …, operationn

«control»/self : OnlineShop

«key» cartId = abc

«entity»/c : Cart

«key» productNo = deftitle

«entity»/pr : Product

Page 11: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Model-driven Unit Testing

Test CasesOperation under Test

Comparator

Test Case Input Actual Result

Expected Output

Pass/No Pass

Test Oracle

Test Case Input

Models

generate generate

1

23

4

Page 12: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Test CasesinputreportPass/

No Pass

Model-Driven Unit Testing

Development Process + Testing

Implementation

Design modelmodels

compile

Operation

Test Oracle + Comparator

completes

generate

Executable Binary Code

Visual Contracts

Java Class skeletons

Class Diagram

generate

AssertionsComplete, executable

applicationProgrammer

Designer

VC Workbench

JML Compiler

JMLUnit

JML

Page 13: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Conclusion

To do:• Discussions on MoDeVa and

other platforms• Applying on a bigger case study• Further reasearch with the aim of

a dissertation

• Visual contracts for behavioral specification

• Generation of– Test oracles– Test cases

• Development Process and existing tools– Editor for visual contracts– Model checking tool– Test driver

Test CasesOperation under Test

ComparatorTest Case Input Actual Result

Expected Output

Pass/No Pass

Test OracleTest Case Input

Models

generate generate

1

23

4

Page 14: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Thank you for your attention!Any questions?

Page 15: Unit Testing

© s-lab, University of Paderborn - http://s-lab.upb.de

Engels, Güldali, Lohmann: Towards Model-Driven Unit Testing

Contact

Software Quality Lab

University of PaderbornWarburger Str. 10033098 PaderbornGermany

http://s-lab.upb.de

Baris Gü[email protected]

Telefon: +49 5251-60 53 91

Fax: +49 5251-60 34 31