+ All Categories
Home > Documents > -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone...

-- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone...

Date post: 14-Dec-2015
Category:
Upload: isaiah-hood
View: 215 times
Download: 0 times
Share this document with a friend
26
-- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder
Transcript
Page 1: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

-- Finishing Design Unit-- Intro to Glass Box Testing

ECEN5543 / CSCI 5548 SW Eng of Standalone Programs

University of Colorado, Boulder

Page 2: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Many Examples

Pure Fabrication – an idea to group together some common behaviorMany OO design patterns are examples

AdapterStrategyCommand...

Traditional cohesion – top two strongestinformationalfunctional

Page 3: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Introduction to Glass Box Testing

TestingSoftware Engineering of Standalone

Programs

Page 4: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

What is Glass Box Testing?Sometimes called Structure TestsExercise the internal logic of a program and traverse particular execution paths

(Functional, performance, and stress testing are collectively referred to as black box testing.)

Page 5: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

What are major activities?Decide which paths need to be exercised.Derive test data to exercise those paths.Determine the test coverage criterion.Execute the test cases.Measure the test coverage achieved.

Page 6: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Why determine test coverage criterion?

Why not just test it all?What does “all” mean?Program units (classes, clusters of classes) usually contain too many paths to permit exhaustive testing.For example, loops introduce combinatorial numbers of execution paths and make exhaustive testing impossible.

Page 7: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

What if you could test all paths?

Would the program be correct then?The program might be missing paths

Code for branch alternative not thereMore likely detect missing paths how?

Might have computational errors not revealed in the test data shown, even on the path where the error occurs

We call that coincidental correctnessFor example, suppose code has x = A + A where it should have A*A but you test with A = 2.

Page 8: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

When are you done with unit testing? Decide on criterion

Statement coverageBranch coverageLogical path coverage

1 5

4

3

2

Page 9: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Statement CoverageFind a set of test cases to ensure that every statement is executed at least once

Page 10: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Branch coverageFind a set of test cases to ensure that each branching statement is taken in each direction at least onceHow is that different from statement coverage?

Page 11: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Logical Path CoverageAcknowledges that the order in which branches are taken can be significantEnsure that every path is executed at least onceA path is some feasible combination of statements and branchesNot in your life time ...

Page 12: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Branch Testing -- May not accomplish what you think

Consider the following pseudocode:if (X > 3 and then Y = 2) then

Z := 1endif;if (X = 4 or else Z > 3) then

Z := Z + 1;endif;What happens with test case x=5,

y=2, z=3 and x=4, y=3, z=3?

Page 13: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Common rule of thumb re unit test completion

85 to 90 % of branch coveragethat is, 85 to 90% of all branch alternatives have been traversed by the set of unit test cases.

Strikes a balance between excessive number of test cases and leaving test completion to the intuition of each programmer

According to studies, functional + performance + stress tests based on functional requirements and programmer’s intuition achieve ....

Page 14: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Limitations

May not be possible to reach 100% branch coverage because it may be hard to find input data that will exercise a nested branching statement in a particular way.Beware of trend plots

# errors discovered per unit of time vs. timeExpect buildup to maximum value and then trail offProblems with this?

Page 15: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Control Flow Diagrams

Provide visual representation of flow of control

IFWhileFor“Do until”Case

Page 16: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Control flow examples - 1

Page 17: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Control flow examples - 2

Page 18: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Control flow examples - 3

Page 19: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Control flow examples - 4

Page 20: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Why look at control flow?Easy to spot complexityEasy to develop basis set for statement coverage

Page 21: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Complexity leads to faults

What do you find makes code hard to understand?What does the control flow diagram look like for that?McCabe’s Cyclomatic Complexity

What is being measured? Number of branchesNumber of closed regions

What is NOT being measured?

Beware: you can analyze YOUR error data against your modules and determine what characteristics are fault-prone in your application area.

Page 22: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Basis set for statement coverage testing

Draw the flow graphCount the regions including the “outside”

N is the number of linearly independent paths through the program control structureA linearly independent path includes one node of the control flow graph not contained in any otherCreate a basis set of linearly independent paths

Prepare test cases to force execution of each path in the basis set.Execution of these test cases yields ______ coverage

Page 23: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

Code sample

/* Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.* Permission to use, copy, modify, and distribute this software and its documentation for * NON-COMMERCIAL purposes and without fee is hereby granted provided that this * copyright notice appears in all copies. Please refer to the file “copyright.html” for * further important copyright and licensing information.

Page 24: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE

* SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED,

* INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF

* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-

* INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES

* SUFFERED BY LINCENSEE AS A RESULT OF USING, MODIFYING OR

* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.

Page 25: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

import java.io.*;import java.util.vector; class ListOfNumbers {

private Vector victor;final int size = 10;

 public ListOfNumbers () {

int i;victor = new Vector(size);for (i = 0; i < size; i++)

victor.addElement(new Interger(i));}

Page 26: -- Finishing Design Unit -- Intro to Glass Box Testing ECEN5543 / CSCI 5548 SW Eng of Standalone Programs University of Colorado, Boulder.

public void writeList() {PrintStream pStr = null;

 System.out.println(“Entering try

statement”);int i;pStr = new PrintStream(new BufferedOutputStream(new FileOutputStream(“OutFile.txt”)));

  for (i = 0; i < size; i++)pStr.println(“Value at: “ + i + “ = “ +

victor.elementAt(i));pStr.close()

}}


Recommended