Using UML, Patterns, and Java Object-Oriented Software Engineering 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 test Integration strategy From TP System decomposition From SDD Functional requirements From RAD Continued on next slide Object designUnit test From ODD Management plan Test planning User interface design Usability test From RAD Continued on next slide
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 Figure 11-1 (continued from previous slide). Acceptance test User manual Performance test Daily operationFunctional testInstallation test Field test UserClientDeveloper From RAD Functional requirements From RAD Nonfunctional requirements Project agreement
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 FailureFaultError Test suite is caused by * * CorrectionComponent Test stub Test driver exercises is revised by findsrepairs * ** * * * 1…n * *
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5 Figure 11-3, An example of a fault.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6 Figure 11-6, An example of an error.
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.
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.
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:TestCaseTestC:TestCase precedes
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 [year < 1] [month in (1,3,5,7,10,12)] n=32 throw2n=29 return throw1 n=28 n=30 [month in (4,6,9,11)] [month == 2][leap(year)]
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 */
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; }... }
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 and derived tests. [(year%4) == 0)] leap=true leap=false return
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. pressButtonL pressButtonR 2. pressButtonL pressButtonR 6.
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() WaveLANUMTS close() receive() send() receive() Ethernet setNetworkInterface() LocationManager Application open() close() send() receive() open() close() send() receive() open() close() send() receive()
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 [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()
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
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 test B,E,F Event Service (C) Double test D,G
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 tests A,B; A,C; A,D Event Service (C) Quad test A,B,C,D
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,CTest A,B,C,D E,F,G Test A,B,C,D, Test E Test F Top layer Bottom layer Figure 11-21, Sandwich testing strategy.
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,CTest A,B,C,D E,F,G Test 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.
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 >
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23 Figure 11-26, Example of a PERT chart for a schedule of the sandwich tests shown in Figure 9-19.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24 Figure 11-27, JUnit test framework. Test TestCaseTestSuite TestResult run(TestResult) setUp() tearDown() testName:String run(TestResult) runTest() run(TestResult) addTest() ConcreteTestCase setUp() tearDown() runTest()