Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Software Testing and Quality Assurance Lecture 20 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)

Similar presentations


Presentation on theme: "1 Software Testing and Quality Assurance Lecture 20 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)"— Presentation transcript:

1 1 Software Testing and Quality Assurance Lecture 20 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)

2 2 Lecture Outline To know what to consider when testing a class. To identify test cases for testing a class.

3 3 Class testing A class is the fundamental unit of an object-oriented program. Class testing comprises the activities associated with verifying that the implementation of a class corresponds exactly with the specification for that class.

4 4 Class testing Class testing is roughly analogous to unit testing in traditional testing processes. The main focus is on execution-based testing.

5 5 Class testing (cont...) Assumptions: Class Under Test (CUT) has a complete specification expressed in a specification language like Object Constraint Language (OCL), a natural language, and/or state transition diagram If more than one form of specification is used for a class: All forms are consistent. Information can be taken from any model.

6 6 Class testing: ways to test a class Reviews: Reviews are subject to human error. Reviews require considerably more effort with respect to regression testing. Executing test cases: Considerable effort can be required for the identification of test cases and the development of test drivers.

7 7 Class testing and unit testing The purpose of unit testing is to ensure that each unit meets its specification. If the unit meets its specification, then any bugs that appear when units are integrated are more likely caused by incorrect interfacing of units. Unit testing is done as units are developed.

8 8 Class testing and unit testing Units are tested by code inspection and execution testing (more emphasis on execution testing). Units that have parameters can be unit tested if the driver can initialize the actual parameters. Should test driver itself be tested?

9 9 Class testing and unit testing (cont...) Identify test cases Test driver construction: create one or more instances of a class to run a test case Execution Result analysis

10 10 Class testing: dimensions of class testing Should we test a class independently as a unit or as a component of a larger part of the system, this decision is based on: The role of the class in the system; the risk associated with it.

11 11 Class testing: dimensions of class testing The complexity of the class measured in terms of: The number of states Operations Associations with other classes The amount of effort associated with developing a test driver for the class.

12 12 Class testing: dimensions of class testing (cont...) Who — developer What — code implements the specification exactly When — A test plan should be developed soon after the specification of the class is ready for coding

13 13 Class testing: dimensions of class testing (cont...) Class testing should be done prior to its use in other portion of the software Regression class testing should be performed whenever the class implementation is changed

14 14 Class testing: dimensions of class testing (cont...) How — develop a test driver that creates instances of the class and sets up a suitable environment around these instances to run a test case How much — Test operations and state transitions in all sorts of combinations Exhaustive or selective with combination with risk analysis.

15 15 Constructing test cases Possible ways for identifying test cases Class specification Pre- and post-conditions (OCL) State transition diagram Class implementation

16 16 Constructing test cases Test case construction from Pre- and Post-conditions Programming style: defensive vs. contract Steps in generating test cases from Pre- and Post-conditions Identify a list of pre-condition contributions Identify a list of post-condition contributions

17 17 Constructing test cases Form test case requirements by making all possible combinations of entries from the contributions lists Eliminate any conditions generated that are not meaningful

18 18 Constructing test cases: Example Velocity class as specified in UML model (Figure 5.2) Velocity speed: Speed direction: Direction Velocity() Velocity (speed: Speed, direction: Direction) getSpeed(): Speed getSpeedX(): Speed getSpeedY(): Speed getDirection(): Direction setSpeed(speed: Speed) setDirection(direction: Direction) Reverse() ReverseX() ReverseY()

19 19 Constructing test cases: Example (cont...) OCL specification for the method setDirection of Velocity class Velocity::setDirection(dir:Direct ion) Pre:0 <= dir and dir < 360 Post:direction=dir and speed=speed@pre

20 20 Key points Ways to test a class: reviews and executing test cases The purpose of unit testing is to ensure that each unit meets its specification. Possible ways for identifying test cases Pre- and post-conditions (OCL) State transition diagram


Download ppt "1 Software Testing and Quality Assurance Lecture 20 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)"

Similar presentations


Ads by Google