florida a & m university computer and information science e-learning testing of classes...
TRANSCRIPT
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 1
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of Classes
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 2
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of Classes
Features of classes:
•Attributes
•Behavior/Operations/Methods
•PRIVATE PART is INVISIBLE to the outside.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 3
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesFeature of Classes• Attributes –
• private part • data describing an object• referred to as the STATE• Attribute values determine
BEHAVIOR,• i.e., how the methods react
to messages.
• Attributes – • private part • data describing an object• referred to as the STATE• Attribute values determine
BEHAVIOR,• i.e., how the methods react
to messages.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 4
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesFeature of Classescontd
- 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.
- 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:
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 5
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of Classes (3) PRIVATE PART is (3) PRIVATE PART is
INVISIBLE to the INVISIBLE to the outside.outside.
- Hard to verify effect
of certain public operations. -
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
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 6
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesLimitations 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.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 7
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of Classes (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).
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 8
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesLimitations 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.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 9
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of Classes (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
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 10
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesChallenge #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.
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
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 11
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesChallenge #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.
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.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 12
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesApproach 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)
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 13
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesApproach 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.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 14
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesCHALLENGE #2 -- Consolidating
the class test -
Challenge: A function-driven test mayrequire 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.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 15
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesCHALLENGE #2
-- Contd Strategy: Perform function-driven tests first.
NEXT apply usage- driven testing.
Strategy: Perform function-driven tests first. NEXT apply usage- driven testing.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 16
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesApproach to challenge #2
-- Contd
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
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 17
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesApproach to challenge #2
-- Contd -- tdi_ file contains the expected results
• actual values • description of the effects
- A single trs_ file is producedtrs_ file echoes the tdi_ inputtrs_ file may contains resultsOr description of observed effects
Additional effort may be required to verify that all the expected effects occurred.
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 18
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesApproach to challenge #2
-- Contd
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
Copyright PCSA, Inc Cis4932 (Dr. Ed Jones) Page 19
Florida A & M University Computer and Information Science e-learning
Testing of ClassesTesting of ClassesTable of Contents
Logic overview What is a proposition Proposition and logical operators
What are bit operators
NegationConjunctionDisjunctionExclusive ORImplication
Biconditional