Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 1
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 2 Features of classes: Attributes Behavior/Operations/Methods PRIVATE PART is INVISIBLE to the outside.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 3 Feature of Classes (1)Attributes – private part data describing an object referred to as the STATE Attribute values determine BEHAVIOR, i.e., how the methods react to messages.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 4 Feature of Classes contd - Typically functions (methods) are for manipulating the object: - Set operations -- store values into the state - Inquiry operations – return values of state variable(s) Computation operations – perform computation using state variable, without modifying state variables. Transformational operations – modify state variables. (2) Behavior/Operations/Methods :
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 5 Approaches: (1)Function-Driven. (Divide and Conquer). Test each function (method). If each method works, then the whole class must work. - Use function testing techniques on each method Document test of each function
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 6 Limitations of Function-Driven approach a)Class methods are not independent. Correctness of one requires correctness of other methods. b) Order in which to test methods. c) Ability to test internal/private functions. d)Ability to see the EFFECTS of a function call, when there is an internal state change.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 7 (2) State-Driven. (State = internal/private variables inside class). -Identify relevant states (not every value of every variable is significant). -Ensure all state transitions have been exercised (state-transition coverage).
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 8 Limitations of State Driven approach a) Hard to identify significant states b)Must understand formal specification using state models. c) Hard to get visibility into current internal state.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 9 (3) Semantics/Usage-Driven approach. (Semantics = the intended meaning/usage of objects of a class type) Example: Stack rules. Push before Pop Detection of empty/overflow. - Sequence of calls to public methods required to DO A JOB - valid and invalid sequences - Focus is on correct "external" behavior
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 10 Challenge #1 Why this is important ? Testing requires "finding" the results so that it can be compared to the expected result. When the result is trapped inside an object, one must be able to access it. Gaining access to the internal state
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 11 Challenge #1 contd What is required The class must be modified temporarily to permit access to the internal state. HOWEVER, the goal must be to minimize the intrusiveness of such modifications. Principle: If you modify what you are testing, then you're not testing the original (real) thing.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 12 Approach to Gain Access to Internal State 1)Add "hooks" to the interface of the class (public section) - DATA TYPE: struct instate declaring all the internal state variables - INQUIRY FUNCTIONS: a) Get_State (instate &) -- returns values of all state variables (contd)
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 13 Approach to Gain Access to Internal State contd -SET FUNCTIONS: - a) Set_State (instate &) -- set state variables to the values contained in the state record being passed. - (2) LAST RESORT -- Make EVERYTHING PUBLIC.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 14 Challenge: A function-driven test may require multiple drivers,one per function, along with tdi_ and trs_ and uts_ utl_ files. This creates a data management problem. Moreover, a function-driven test does not address the overall behavior of the class.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 15 Strategy: Perform function-driven tests first. NEXT apply usage- driven testing. Strategy: Perform function-driven tests first. NEXT apply usage- driven testing.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 16 APPROACH: (1) Usage-Driven class test driver - menu driven based on inputs in tdi_ file: -- each menu selection identifies the class method to be invoked. -- tdi_ file contains the "arguments“ needed for the call
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page tdi_ file contains the expected results actual values description of the effects -A single trs_ file is produced trs_ file echoes the tdi_ input trs_ file may contains results Or description of observed effects Additional effort may be required to verify that all the expected effects occurred.
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 18 Identify user tasks (end-to-end) Base tasks on the specification of the class Base other tasks on "boundary conditions“ Identify the sequence of public operations required to perform the task. APPROACH: 2) Usage-Driven Test Case Design
Florida A & M University Computer and Information Science e-learning Testing of Classes Copyright PCSA, Inc Cis4932 (Dr. Ed Jones)Page 19 Table of Contents Logic overview What is a proposition Proposition and logical operators What are bit operators Negation Conjunction Disjunction Exclusive OR Implication Biconditional