Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box...

28
Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms Effective Black-Box Testing with Genetic Algorithms Mark Last and Shay Eyal Department of Information Systems Engineering Ben-Gurion University of the Negev, Beer-Sheva, Israel Abraham Kandel National Institute for Systems Test and Productivity (NISTP) University of South Florida, Tampa, FL, USA IBM Verification Conference 2005

Transcript of Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box...

Page 1: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Effective Black-Box Testing with Genetic Algorithms

Mark Last and Shay EyalDepartment of Information Systems Engineering

Ben-Gurion University of the Negev, Beer-Sheva, Israel

Abraham KandelNational Institute for Systems Test and Productivity (NISTP)

University of South Florida, Tampa, FL, USA

IBM Verification Conference 2005

Page 2: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

2

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Agenda• What is NISTP?• Black-Box Testing: State-of-the-Art• Research Goal and Objectives• Overview of Genetic Algorithms (GA)

– Fuzzy-Based Age Extension of Genetic Algorithms (FAexGA)

• GA-Based Test Case Generation• Initial Case Studies• Summary and Discussion

Page 3: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

3

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

National Institute for Systems Test and Productivity

• University of South Florida, Tampa, FL, USA– College of Engineering: PI - Prof. Abraham Kandel (Executive

Director)– College of Business Administration: CO-PI - Prof. Alan R. Hevner

• Subcontractors– Arizona State University: PI - Dr. Wei-Tek Tsai – Drexel University: PI - Dr. Rosina Weber– QTSI: PI - Chick Garcia – Ben Gurion University: PI - Dr. Mark Last– Echelon: PIs - Dr. Jay Bayne, Dr. Norm Brown

Funding Source: SPAWAR - US Space and Naval Warfare Systems Command (Grant No. N00039-01-1-2248). WWW: http://nistp.csee.usf.edu/

The Institute's mission is to engage in innovative research and to provide direct support to government agencies (and their development agents) which will enable them to substantially reduce cost and improve the development schedule and reliability of large-scale systems

Page 4: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

4

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Functional (Black-Box) Testing• Based on software specification only• Compares the observed outputs to

expected outputs• Needs an “oracle” for a tested system • Exhaustive (combinatorial) testing is

computationally infeasible for large-scale software systems

• BB Test generation methods– Random Testing (within / without the

operational profile)– Special value testing– Boundary value testing– Equivalence classes– Decision tables– Input-Output Analysis

Inputs

Outputs

All BB testing methods cover only a tiny portion of possible software inputs!

Page 5: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

5

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Effective Black-Box Test Cases• Test case

– A particular choice of input data to be used in testing a program• An effective set of test cases

– A test set that has a high probability of detecting faults presenting in a computer program

• Testers’ Objectives– Generate good test cases

• A good test case is one that has a high probability of detecting an as-yet undiscovered error

• Several test cases causing the same bug may show a pattern that might lead to the real cause of the bug

– Prioritize test cases• The dominant criterion: rate of fault detection – how quickly a test

case detect faults during the testing process

Page 6: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

6

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Research Goal and Objectives• Goal

– Develop novel methodology for generation of effective black-box test cases with genetic algorithms

• Basic Idea– Eliminate "bad" test cases that are unlikely to expose any error,

while increasing the number of "good" test cases that have a high probability of producing an erroneous output

• Objectives– Define a general framework for evolving an effective set of test

cases with a genetic algorithm– Enhance the proposed GA-based methodology by the novel Fuzzy-

Based Age Extension of Genetic Algorithms (FAexGA)– Evaluate the effectiveness and the efficiency of the proposed

approach using synthetic and real computer programs

Page 7: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

7

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Overview of Genetic Algorithms (GA)

• Search and optimization method developed by mimicking the evolutionary principles and chromosomal processing in natural genetics

• Application Areas– Optimization: numerical, combinatorial (job-shop

scheduling).– Machine learning tasks: classification, prediction (weights for

neural networks).– Economics: bidding strategies.

““Genetic algorithm is a computerized Genetic algorithm is a computerized simulation of Darwin's theoriessimulation of Darwin's theories””

Holland J. H.Holland J. H.

Page 8: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

8

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

InitializeInitializepopulationpopulation

SelectionSelection

MutationMutation

CrossoverCrossover

Insert intoInsert intopopulationpopulation

Select individuals for mating

Mate individuals

Mutate offspring

Insert offspring into population

Stop criteria satisfied ?

Moving to Moving to the next the next generationgeneration……

AnswerYesNo

GA Working Principle

Page 9: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

9

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

General GA Settings• Solution encoding (binary, real, tree…).• Initialization

– How to create an initial population of potential solutions?• Genetic operators

– Selection method (ranking, roulette wheel…).– Crossover-operator (one-point, uniform…).– Mutation-operator (inversion, flip…).

• Evaluation function– Rate the candidate solutions quality

• Parameter values– N - population size– Pc - crossover probability– Pm - mutation probability– Ngen – number of generations

Page 10: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

10

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Crossover and Mutation

100000011101000

100111100011100

100110011101000

100001100011100

Single-Point Crossover

000 001

010 011

100 101

111110

?

Bit-flip Mutation

Page 11: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

11

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Premature Convergence of GAs

Parameters: population size, crossover probability, etc.

Exploration – overall search in the solution space

Exploitation – localized search in the promising regions discovered so far in thatspace

“Poor parameter setting might make exploitation/exploration relationship (EER) disproportionate,

produce lack of diversity and lead to Premature Convergence”

F. Herrera

Page 12: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

12

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Fuzzy-Based Age Extension of Genetic Algorithms (FAexGA)

(Last and Eyal, 2005)

• Goal – Find an optimal policy for controlling the

Exploration/Exploitation relationship in GA based on the age attribute.

• Age = number of generations

Example:Example:

If A is If A is OldOld and B is and B is OldOld thenthencrossover probability is crossover probability is LowLow

Where A and B are two chromosomes chosen for crossoverWhere A and B are two chromosomes chosen for crossover

Page 13: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

13

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

FAexGA Method• Adapt the crossover probability (Pc) with

Fuzzy Logic Controller (FLC):

Knowledge BaseKnowledge Base

Fuzzificationinterface

Fuzzificationinterface

GAGA

Defuzzificationinterface

Defuzzificationinterface

InferenceSystem

InferenceSystem

State Variables

Control Parameters

• Crossover probability• Lifetime, Age.

Page 14: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

14

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Fuzzification of Age• Age ∈ [Young, Middle-age, Old]

Young Middle-age Old

0.2 0.5 1

Membership Function

1

Relative Age (=age/avg. lifetime)

Young: 0-30%

Middle-age: 20-80%

Old: 70-100%

0.3 0.80.7

Lifetime = number of generations a chromosome stays alive

Page 15: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

15

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Fuzzification of Crossover Probability PC

• Pc ∈ [Low, Medium, High]

• Defuzzification method: Center of Gravity

Low Medium High

0.15 0.5 1

Membership Function

1

Pc

Low: 0-20%

Medium: 15-85%

High: 80-100%

0.2 0.850.8

Page 16: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

16

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Fuzzy-Based Age Extension of GARandom Random

Initialize P(t)Initialize P(t)

P(t) = population on generation t.

Evaluate P(t)Evaluate P(t) Increase AgeIncrease Age

SelectionSelection

Assign PcAssign Pc

MutationMutation

CrossoverCrossover

Remove Individuals Remove Individuals with age > lifetime with age > lifetime

Evaluate P(t)Evaluate P(t)

AnswerAnswerAnswer

Moving to Moving to the next the next generationgeneration……

Stop criteria satisfied ?

Call Fuzzy Logic Controller

Page 17: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

17

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Fuzzy Rule Base• Age ∈ [Young, Middle-age, Old]• Crossover Probability Pc ∈ [Low, Medium, High]

• Inference method: MAX-MIN

LowMedium Low“Old”

Medium HighMedium“middle-age”

LowMediumLow“Young”

“Old”“middle-age”“Young”Parent IParent II

Page 18: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

18

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

GA-Based Test Case Generation• Representation

– Each test case can be represented as a vector of binary or continuous values related to the inputs of the tested software

• Initialization – An initial test set can be generated randomly in the space of

possible input values.• Genetic operators.

– Selection, crossover, and mutation operators can be adapted to representation of test cases for a specific program.

• Evaluation function. – Test cases can be evaluated by their fault-exposing-potential using

buggy (mutated) versions of the original program.

Page 19: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

19

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Design of Experiments• Tested Algorithms:

– Simple GA [Goldberg]. – GA with varying population size (GAVaPS).– Crisp Age extension of GA.– Fuzzy-based Age extension of GA (three configurations).

80%

20%

FAexGA#3

75%70%FLC – “Old”lower limit

25%30%FLC – “Young”upper limit

FAexGA#2FAexGA#1Parameter

Page 20: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

20

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Evaluation Measures

# runs yielding the optimal solutiontotal number of runs

max

1 gug

= −

min

max min

d dGDd d

−=

bestfPDf

=November 13, 2005 Shay Eyal 24

f = fitnessf = fitnessPhenotypicalPhenotypical diversitydiversity

d=distance from the best solutiond=distance from the best solution

Genotypical diversityGenotypical diversity

g = # of g = # of generations for the first solutiongenerations for the first solution

UnuseUnuse factorfactor

Solution QualitySolution Quality

FormulaFormulaPerformance Performance measuremeasure

# runs yielding the optimal solutiontotal number of runs

max

1 gug

= −

min

max min

d dGDd d

−=

bestfPDf

=

Page 21: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

21

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Case Study 1: Boolean Expression • Correct version - Boolean expression composed of 100

attributes and three logical operators: AND, OR, and NOT. – This expression is generated randomly using an external

application– Number of combinatorial test cases: 2100

• Erroneous version - same Boolean expression as the correct one, except for a single error injected in the correct expression by randomly selecting an OR operator and flipping it to the AND one (or vice versa).

• GA parameters:– Number of generations = 200.– Population size = 100.– Chromosome length = 100.– Crossover probability = 0.9 (for simple GA and GAVaPS).– Mutation probability = 0.01– Discrete evaluation function (Error = Yes / No)

Page 22: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

22

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Boolean Expression Results

• FAexGA#1 reached a solution in most of the runs with significantdifferences compared to the others algorithms.

• FAexGA#1 averaged the highest number of solutions (this should assist locating the error).

• FAexGA#1 averaged the highest Unuse factor

Measure\Algorithm

SimpleGA GAVaPS FAexGA#1 FAexGA#2 FAexGA#3

% Runs with solution 70% 60% 95% 70% 75%

% Solutions in the final population 1.27% 81.52% 99.93% 98.86% 87.18%

Unuse Factor 65.57% 62.27% 70.66% 68.71% 46.27%

Page 23: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

23

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Boolean Expression Results (cont.)%Solutions

0

0.2

0.4

0.6

0.8

1

1.2

1 200 Generations

%

Solu

tions

SimpleGA

GAVaPS

FAex#1

FAex#2

FAex#3

Page 24: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

24

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Case Study 2: Credit Application(Source: Last and Kandel, 2003)

• Number of inputs: 8– Five nominal and three continuous

• Number of outputs: 2– Decision (accept / reject)

– Credit limit (continuous)

• Physical lines of code: 63

• Number of program flow paths: 52

• Number of combinatorial tests: 11,312,000

Page 25: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

25

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Credit Application ResultsAverage of 10 runs

0

0.2

0.4

0.6

0.8

1

1 5 9 13 17 21 25 29 33 37 41 45 49

Generation

#Sol

utio

n/To

tal_

Pop

FAex#1

Page 26: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

26

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Summary• We have introduced a new, GA-based approach to generation of

effective black-box test cases• The Fuzzy-Based Age Extension of Genetic Algorithm (FAexGA)

appears to be much more efficient for this problem than the two other evaluated algorithms (SimpleGA and GAVaPS):

– FAexGA has a much higher probability to find an error in the tested software

– The error would be found much faster, which should result in saving a lot of resources for the testing team.

– In addition, the number of distinct solutions produced by FAexGA is significantly higher, which may be useful for investigation and identification of the error itself by the software programmers

• Future research– Experimentation with larger software programs– Development of more sophisticated, possibly continuous evaluation

functions

Page 27: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

27

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Acknowledgments

• This work was partially supported by the National Institute for Systems Test and Productivity at University of South Florida under the USA Space and Naval Warfare Systems Command Grant No. N00039-01-1-2248 and by the Fulbright Foundation that has awarded Prof. Kandel the Fulbright Senior Specialists Grant at Ben-Gurion University of the Negev in November-December 2005.

Page 28: Effective Black-Box Testing with Genetic · PDF file3 Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms National Institute for Systems Test and Productivity •

28

Dr. Mark Last (BGU) Effective Black-Box Testing with Genetic Algorithms

Related Publications• Books

– M. Last, A. Kandel, and H. Bunke (Editors), “Artificial Intelligence Methods in Software Testing”. World Scientific, Series in Machine Perception and ArtificialIntelligence, Vol. 56, 2004.

• Papers– M. Last and A. Kandel, “Automated Test Reduction Using an Info-Fuzzy

Network”, T.M. Khoshgoftaar (Ed.), Software Engineering with Computational Intelligence, Kluwer Academic Publishers, pp. 235 – 258, 2003.

– M. Last, M. Friedman, and A. Kandel, “The Data Mining Approach to Automated Software Testing", Proceedings of the Ninth ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD-2003), pp. 388 - 396, Washington, DC, USA August 24 - 27, 2003

– M. Last, M. Friedman, and A. Kandel, “Using Data Mining for Automated Software Testing", International Journal of Software Engineering and Knowledge Engineering (IJSEKE), Special Issue on Data Mining for Software Engineering and Knowledge Engineering, Vol. 14, No. 4, pp. 369-393, August 2004.

– M. Last and S. Eyal, A Fuzzy-Based Lifetime Extension of Genetic Algorithms, Fuzzy Sets and Systems, Vol. 149, Issue 1, January 2005, 131-147.