Rajib Mall Lecture Notes
Rajib Mall Lecture Notes
Rajib Mall Lecture Notes
Introduction
More than 50% of development effort is being spent on testing. Quality and effective reuse of software depend to a large extent: on thorough testing. It was expected during initial years that OO would help substantially reduce testing effort: But, as we find it out today --- it only complicates testing.
3
Todays Focus
Most reported research on OO paradigms focus on: Analysis and design. We discuss some important issues in testing object-oriented systems.
Fault Model
Different types of faults in a program: Infinite for practical purposes . A fault model: A map of possible types of faults. Necessary to guide any rational testing strategy. A fault model may be constructed from analysis of failure data.
5
Challenges in OO Testing
What is an appropriate unit for testing? Implications of OO features: Encapsulation Inheritance Polymorphism & Dynamic Binding, etc. State-based testing Test coverage analysis Integration strategies Test process strategy
7
What is the fundamental unit of testing for conventional programs? A function. However, as far as OO programs are concerned: Methods are not the basic unit of testing. Weyukar's Anticomposition axiom: Any amount of testing of individual methods can not ensure that a class has been satisfactorily tested.
8
cont
Tests the interactions among a group of cooperating classes. A sequence of interactions is typically required to implement a visible behavior (i.e. a use case). System level: Tests an entire operational system.
10
Encapsulation
Encapsulation is not a source of errors: However, an obstacle to testing. It prevents accessing attribute values by a debugger. While testing: Precise information about current state is necessary.
11
13
Inheritance
Should inherited methods be retested? Retesting of inherited methods is the rule, rather than an exception. Retesting required: Because a new context of usage results when a subclass is derived. Correct behavior at an upper level: Does not guarantee correct behavior at a lower level.
14
Polymorphism
Each possible binding of a polymorphic component requires separate testing: Often difficult to find all bindings that may occur. Increases the chances of bugs . An obstacle to reaching coverage goals.
19
Polymorphism
Polymorphism complicates integration planning:
cont
Many server classes may need to be integrated before a client class can be tested.
C S1 S2
20
S3
Dynamic Binding
Dynamic binding implies: The code that implements a given function is unknown until run time. Static analysis cannot be used to identify the precise dependencies in a program. It becomes difficult to identify all possible bindings and test them.
21
State-Based Testing
The concept of control flow of a conventional program : Does not map readily to an OO program. In a state model: We specify how the object's state would change under certain conditions.
22
State-Based Testing
Flow of control in OO programs: Message passing from one object to another. Causes the receiving object to perform some operation, can lead to an alteration of its state.
23
State-Based Testing
The state model defines the allowable transitions at each state. States can be constructed: Using equivalence classes defined on the instance variables. Jacobson's OOSE advocates: Design test cases to cover all state transitions.
24
cont...
State-Based Testing
cont the Test cases can be derived from... state machine model of a class: Methods result in state transitions. Test cases are designed to exercise each transition at a state. However, the transitions are tied to user-selectable activation sequences: Use Cases
25
Test Coverage
Test coverage analysis: Helps determine the thoroughness of testing achieved. Several coverage analysis criteria for traditional programs have been proposed: What is a coverage criterion? Tests that are adequate w.r.t a criterion: Cover all elements of the domain determined by that criterion.
27
cont... But, what are the elements that characterize an object-oriented program? Certainly different from procedural programs. For example: Statement coverage is not appropriate due to inheritance and polymorphism. Appropriate test coverage criteria are needed.
28
Test Coverage
Criterion
Integration Strategies
Essentially two approaches exist: Thread-based Use-based
29
UML has become the de facto standard for OO modeling and design: Though UML is intended to produce rigorous models: Does incorporate many flexibilities. Incomplete, inconsistent, and ambiguous models often result. Never the less: UML models are an important source of information for test design.
34
35
Inheritance, Association, Composition, and Dependency. Each relationship has corresponding generic test requirements: For example, a generalization relation is:
not Reflexive(R) and not Symmetric(S) but is Transitive(T)
36
Testing Relations
For any relation, we can ask which of the three (R, S, T) properties is required, excluded, or irrelevant. The answers leads to a simple but effective test suite.
cont...
37
Testing Relations
cont...
For example, when reflexivity is excluded, Any x that would make xRx true should be rejected. Example: Student is member of DeptLibrary and Dept-Library is a part of Dept. The relation is member of is not R, not S but is T.
38
40
Generic test requirements include: At least one test case should exercise:
Every Use Case when actor communicates with Use Case. Every extension combination such as Use Case 1 extends Use Case 2. Every uses combination such as Use Case 1 uses Use Case 2.
41
Class Diagram
Documents the structure of a system: Represents the entities and their interrelationships. Test cases should exercise: Each association. Independent creation and destruction of the container and the components in an aggregation relation. Each inherited method should be retested.
42
Sequence Diagram
A sequence diagram documents message exchanges in time dimension. Generic tests include: Message coverage: At least one test case should exercise each message. Message path coverage: All end-to-end paths should be identified and exercised.
43
Diagrams
cont
45
Activity Diagram
Activity diagrams are based on: Flow charts, state transition diagrams, flow graphs and Petri nets. Can be considered to be an extension of flow chart: Can represent two or more threads of concurrent execution. Supports all features of a basic flow graph: Can be used to develop test models for control flow based techniques. 46
Activity Diagram
Decision tables
cont...
Activity diagram can be used to construct: Composite control flow graph representing a collection of sequence diagrams. Control flow graph at method scope:
This may be useful to analyze path coverage.
47
Activity Diagram
Generic test requirements:
cont...
Synch Point is followed by Action Action is started after Signal Synch Point is reached after
Action
48
Statechart Diagram
Can be used to represents statebased behavior of : a class, subsystem, or system. Statechart model: Provides most of the information necessary for class-level state-based testing.
49
Collaboration Diagram
Represents interactions among objects. A collaboration diagram specifies: The implementation of a use case. May also depict the participants in design patterns.
50
Collaboration Diagram
Each collaboration diagram represents only one slice of the IUT. A composite collaboration diagram would be necessary: To develop a complete test suite for an implementation.
51
cont...
Component Diagram
Shows the dependency relationships among: Components, Physical containment of components, Interfaces and calling components. The basic testing practice with respect to component diagrams: All call paths should be identified and exercised.
52
Deployment Diagram
Represents hardware, software, and network architecture. Useful in integration planning. When a component runs on a node, Test cases should exercise whether a component can be loaded and run on each designated host node. When a node communicates with another node, Test cases should exercise open, transmit, and close communication for each remote component.
53
GN criterion fault model: Likely to reveal faults that can arise from violation of the substitutability principle.
55
Substitutability Principle
Given a test set T , a system model SM, and a class C, T must cause
A set of representative attribute value combinations in each instance of class C must be created.
The value space of attributes provides an opportunity to develop test criteria. The value space of an attribute are usually restricted by OCL constraints. Example: age attribute in Customer class can have a constraint age >18
57
Given a test set T and collaboration diagram CD, T must cause: Each clause in every condition in CD to take the values of TRUE and FALSE. A condition may consist of more than one clause connected by Boolean operators (e.g., AND, OR)
59
Message on each link connecting two objects in CD to be exercised at least once. This criterion ensures: All possible messages between two objects occur during tests.
60
A message path is a sequence of messages. All message paths is a stronger criterion than message on each link criterion.
61
63
cont...
Patterns developed under different scope of testing: Scope Example Pattern Method scope Polymorphic Message Test Class Scope Modal Class Test Reusable Components Abstract Class Test Subsystem Round-trip Scenario Test Integration Collaboration Integration Application Scope Extended Use Case Pattern Regression Test Retest Within Firewall
64
EUC Intent
Model the input output relationships in a use case using a decision table. It then becomes possible to develop test cases: By considering specific inputs for a use case and corresponding expected results.
66
EUC Context
Unless test points are systematically selected based on a use cases implicit constraints and relationships:
cont...
All fundamental relationships would not be exercised. Example: A Use Case Pay-Fees can be a generalization of Pay-by-Credit-Card and Pay-by-Cash Use Cases
67
Domain error: Incorrect Pin code Logic Error: Sales registered against an invalid customer code.
68
cont...
69
70
Operational variables:
Factors which vary from one scenario to the next. Determines different system responses. Explicit inputs and outputs. Environmental conditions which result in significantly different behavior. Abstractions of the state of the system. 72
The domains are developed by defining: The valid and invalid values for each variable.
73
Operational variables:
May determine distinct classes of system responses. Express them in the form of a decision table: When all the conditions in a row are true, the expected action is to be produced.
74
75
76
Domain Constraint: An object of class Account will not accept a withdrawal message if the balance is less than 0. Sequence Constraint: In the frozen state, an Account object can accept a credit or debit message only after an unfreeze message.
77
78
A class may fail to implement its state model in five ways: 1. Missing transition: A valid message is rejected in a valid state. 2. Incorrect action: A wrong response for an accepting state and valid message. 3. Invalid resultant state: A message results in transition to a wrong state. 4. Invalid state: An invalid state is produced. 5. Sneak path: A sneak path allows a wrong message to be accepted.
79
82
For each conditional transition : Develop a truth table for the variables in the condition. Develop an additional test case: For each entry in the truth table that is not already exercised.
83
Example Heuristics:
1. Begin with the simplest and finish with the most complex. 2. Begin with the collaboration that requires the fewest stubs . 3. Test in order of risk of disruption of system testing.
88
4. Develop test suite for each collaboration 5. Run the test suite and debug until first collaboration passes 6. Continue until all collaborations have been exercised
89