Art for Chapter 11, Testing

24
Using UML, Patterns, and Java Object-Oriented Software Engineering Art for Chapter 11, Testing

description

Art for Chapter 11, Testing. Management plan. Test planning. User interface design. Object design. Unit test. From ODD. From RAD. From TP. From RAD. Continued on next slide. Continued on next slide. - PowerPoint PPT Presentation

Transcript of Art for Chapter 11, Testing

Page 1: Art for Chapter 11, Testing

Usi

ng U

ML

, Pat

tern

s, a

nd J

ava

Ob

ject

-Ori

ente

d S

oftw

are

En

gin

eeri

ng

Art forChapter 11, Testing

Page 2: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2

Figure 11-1, Testing activities and their related work products (continued on next slide).

Functional test

Structure test

UserClientDeveloper

Integration testIntegrationstrategy

From TP

Systemdecomposition

From SDD

Functionalrequirements

From RAD

Continuedon next slide

Object design Unit test

From ODD

Managementplan

Test planningUser interface

designUsability test

From RAD

Continuedon next slide

Page 3: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3

Figu

re 11-1 (contin

ued

from previou

s slide).

Acceptance test

User manual

Performance test

Daily operation

Functional test

Installation test

Field test

UserClientDeveloper

From RAD

Functionalrequirements

From RAD

Nonfunctionalrequirements

Projectagreement

Page 4: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4

Figure 11-2, Model elements used during testing.

is caused by

* *

Test case

Failure FaultError

Test suite

is caused by

*

*

CorrectionComponent

Test stub

Test driver

exercises is revised by

finds repairs

*

* *

*

* * 1…n

*

*

Page 5: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5

Figure 11-3, An example of a fault.

Page 6: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6

Figure 11-6, An example of an error.

Page 7: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7

Figure 11-7, A fault can have an algorithmic cause.

Page 8: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8

Figure 11-8, A fault can have a mechanical cause, such as an earthquake.

Page 9: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9

Figure 11-9, Test model with test cases.

TestA:TestCase

TestA1:TestCase

TestA2:TestCase

TestB:TestCase TestC:TestCase

precedes precedes

Page 10: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10

Figure 11-11, Equivalent flow graph for the getNumDaysInMonth() method implementation of Figure 11-12.

[year < 1]

[month in (1,3,5,7,10,12)]n=32

throw2 n=29

return

throw1

n=28

n=30[month in (4,6,9,11)]

[month == 2] [leap(year)]

Page 11: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11

Figure 11-12, An example of a (faulty) implementation of the getNumDaysInMonth() method (Java). (continued on next slide)

public class MonthOutOfBounds extends Exception {…};public class YearOutOfBounds extends Exception {…};

public class MyGregorianCalendar {public static boolean isLeapYear(int year) {

boolean leap;if (year%4) {

leap = true;} else {

leap = false;}return leap;

}

/* … continued on next slide */

Page 12: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12

Figure 11-12, An example of a (faulty) implementation of the getNumDaysInMonth() method (Java). (continued from previous slide)

/* … continued from previous slide */public static int getNumDaysInMonth(int month, int year)

throws MonthOutOfBounds, YearOutOfBounds {int numDays;if (year < 1) {

throw new YearOutOfBounds(year);}if (month == 1 || month == 3 || month == 5 || month == 7 ||

month == 10 || month == 12) {numDays = 32;

} else if (month == 4 || month == 6 || month == 9 || month == 11) {numDays = 30;

} else if (month == 2) {if (isLeapYear(year)) {

numDays = 29;} else {

numDays = 28;}

} else {throw new MonthOutOfBounds(month);

}return numDays;

}...}

Page 13: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13

Figure 11-13, Equivalent flow graph for the (faulty) isLeapYear() method implementation of Figure 11-12 and derived tests.

[(year%4) == 0)]leap=true

leap=false

return

Page 14: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14

Figure 11-14, UML statechart diagram and resulting tests for 2Bwatch set time function. (test cases on next slide)

MeasureTime SetTime

3.pressButtonsLAndR

5.pressButtonsLAndR/beep

4.after 2 min.

DeadBattery

8.after 20 years7.after 20 years

1.

pressButtonLpressButtonR

2.pressButtonLpressButtonR

6.

Page 15: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15

Figure 11-15, A Strategy pattern for encapsulating multiple implementations of a NetworkInterface.

NetworkConnection

send()

NetworkInterface

open()

WaveLAN UMTS

close()receive()send()receive()

Ethernet

setNetworkInterface()

LocationManager

Application

open()close()send()receive()

open()close()send()receive()

open()close()send()receive()

Page 16: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16

Figure 11-17, Equivalent flow graph for the expanded source code of the NetworkConnection.send() method of Figure 11-16.

[nif instanceof Ethernet]

[nif instanceof WaveLAN]wNif.isReady()

eNif.isReady()

uNif.isReady()

[ready]

[nif instanceof Ethernet]

[nif instanceof WaveLAN]

;

wNif.send()

eNif.send()

uNif.send()

Page 17: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17

Figure 11-18, Example of a hierarchal system decomposition with three layers.

User Interface (A)

Billing (B) Event Service (C) Learning (D)

Database (E) Network (F) Neural Network (G)

Layer III

Layer II

Layer I

Page 18: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18

Figure 11-19, Bottom up test strategy. After unit testing subsystems E, F, and G, the bottom up integration test proceeds with the triple test B,E,F and the double test D,G.

Database (E) Network (F) Neural Network (G)

User Interface (A)

Billing (B) Learning (D)

Triple testB,E,F

Event Service (C)

Double testD,G

Page 19: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19

Figure 11-20, Top down test strategy. After unit testing subsystem A, the integration test proceeds with the double tests (A,B), (A,C), and (A,D), followed by the quad test (A,B,C,D).

Database (E) Network (F) Neural Network (G)

User Interface (A)

Billing (B) Learning (D)

Double testsA,B; A,C; A,D

Event Service (C)

Quad test

A,B,C,D

Page 20: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20

Test A

Test G

Test B,E,F

Test D,G

Test A,D

Test A,B

Test A,C Test A,B,C,D

E,F,GTest A,B,C,D,

Test E

Test F

Top layer

Bottom layer

Figure 11-21, Sandwich testing strategy.

Page 21: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21

Test A

Test G

Test B,E,F

Test D,G

Test A,D

Test A,B

Test A,C Test A,B,C,D

E,F,GTest A,B,C,D,

Test E

Test F

Test B

Test C

Test D

Top layer

Target layer

Bottom layer

Figure 11-22, An example of modified sandwich testing strategy.

Page 22: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22

Figure 11-23, An example of use case model for a subway ticket distributor.

PurchaseTicket

Passenger

OutOfOrder

Cancel

NoChange

TimeOut<<extends>>

<<extends>><<extends>>

<<extends>>

Page 23: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23

Test A

1Nov 13

1dNov 14

Test A, B

5Nov 14

1dNov 15

Test A, C

6Nov 14

1dNov 15

Test A, D

7Nov 14

1dNov 15

Test A, B, C, D

10Nov 15

1dNov 16

Test G

2Nov 13

1dNov 14

Test F

3Nov 13

1dNov 14

Test E

4Nov 13

1dNov 14

Test D, G

8Nov 14

1dNov 15

Test B, E, F

9Nov 14

1dNov 15

Test A,B,C,D,E,F,G

11Nov 16

1dNov 17

Figure 11-26, Example of a PERT chart for a schedule of the sandwich tests shown in Figure 9-19.

Page 24: Art for Chapter 11, Testing

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24

Figure 11-27, JUnit test framework.

Test

TestCase TestSuite

TestResult

run(TestResult)setUp()tearDown()

testName:String

run(TestResult)

runTest()

run(TestResult)addTest()

ConcreteTestCase

setUp()tearDown()runTest()