Top Banner
Implementation of Algorithm for Logic Based Testing Dissertation Submitted in fulfillment of the Requirement for the award of the Degree Master of Technology (IT) Of Banasthali Vidyapith Jaipur Campus 2009-2011 Under The Supervision Of: Submitted By: Mrs. Usha Badhera Priyanka Gaur Astt. Professor(AIM & ACT) M.Tech. (IT) Banasthali Vidyapith, Jaipur Campus Roll No. - 11428
45

Gaur11428

Jul 05, 2015

Download

Internet

Priyanka Gaur
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gaur11428

Implementation of Algorithm for

Logic Based Testing

Dissertation

Submitted in fulfillment of the

Requirement for the award of the Degree

Master of Technology (IT)

Of

Banasthali Vidyapith

Jaipur Campus

2009-2011

Under The Supervision Of: Submitted By:

Mrs. Usha Badhera Priyanka Gaur

Astt. Professor(AIM & ACT) M.Tech. (IT)

Banasthali Vidyapith, Jaipur Campus Roll No. - 11428

Page 2: Gaur11428

Overview• Logic Based Testing

• Cause Effect Graphing Technique

•Application of Genetic Algorithm in Software Testing

• Test cases

• Decision table

• Commonly used Process for CEG

•Analysis of Myer’s CEG Approach

• Possible Solution to Drawback of Myers’ Approach

• Implementation of Converting a Cause Effect Graph into Decision-

Table

•Implementation of Algorithm on Cases

• Screenshots

•Advantages of CEG Technique

Page 3: Gaur11428

• Implementation of Algorithm on Cases

• Screenshots

•Advantages of CEG Technique

•Analysis of Previous and Implemented Algorithm

•Weighted Graph and Path Testing

• Genetic Algorithm

•Advantage of GA in Software Testing

• Generating Effective Test Cases with GA

• Code with weighted Control Flow Diagram

• Working of Algorithm for Control Flow Graph

• Results

• Conclusion

• References

Page 4: Gaur11428

Logic Based Testing

• The functional requirement of many programs can be specified by decision

table , which provide the useful basis for program and test case Design.

• Consistency and completeness can be analyzed by Boolean Algebra, which

can also be used as a basis for test Design.

• Logic based testing translates the specification that are dominated by logic

and combination of test cases into either Decision Table and develop

functional test cases from those representation.

• Cause Effect Graphing technique is used for develops test cases to

represents input events (Causes) and the corresponding actions(output).

Page 5: Gaur11428

Cause Effect Graphing Technique• A cause Effect Graphing is basically a hardware testing technique

adapted to software testing .The CEG technique is a black box

method. This is a testing technique that aids in selecting test cases

that logically relate causes to effect to produce test cases.

• Cause – “A Cause is any distinct input condition in the

requirements that may affect the programs output. A cause is

always positive and atomic”.

• Effect – “An Effect is the response of the program to some

combination of input conditions”.

• Constraints - “ Constraint represent external constraints on the

system”.

Page 6: Gaur11428

Application of Genetic Algorithm in

Software Testing• Automatic Test Case Generation. This Technique extends the random

testing by the use of genetic algorithm.

• GA technique can be applied for finding the most critical path forsoftware testing efficiency.

• The fitness function of GA for selecting the best possible Test Suit.

• This technique is useful where

(i) a program may contain an infinite number of paths when theprogram has loops.

(ii) The number of paths in a program is exponential to the number ofbranches in it and many of them is unfeasible.

(iii) the number of test cases is too large

It is impossible to cover all possible paths in Software, The problemof path testing selects a subset of paths to execute and find test datato cover it.

Page 7: Gaur11428

Decision table• Test Cases: A Good test case is a test case whose chances to

finding a bug are more.

• A Decision Table is the method used to build a complete set oftest cases without using the internal structure of the program inquestion. In order to create test cases we use a table to containthe input and output values of a program.

Basically Decision Table has three parts:

• Condition stubs: Lists condition relevant to decision

• Action stubs: Actions that result from a given set of conditions

• Rules: Specify which actions are to be followed for a given setof conditions.

Page 8: Gaur11428

Commonly used Process for CEGThe commonly used process for CEG can be described in the

following six steps:

• Step 1: Break the specification down into workable pieces.

• Step 2: Identify the causes and effects.

(a) Identify the causes and assign each one a unique number.

(b) Identify the effects or system transformation and assign each

one a unique number.

• Step 3: The semantic content of the specification is analyzed and

transformed into a Boolean graph linking the causes and effects.

This is the cause-effect graph.

Page 9: Gaur11428

Commonly used Process for CEG

• Step 4: Annotate the graph with constraints describing

combinations of causes and/or effects .

• Step 5: Methodically trace state conditions in the graphs,

converting them into a limited-entry decision table. Each column

in the table represents a test case.

• Step 6: The columns in the decision table are converted into test

cases.

Page 10: Gaur11428

Commonly used Process for CEG

Page 11: Gaur11428

Analysis of Myers’ CEG Approach

• Some inconsistencies in

Myers’ CEG Techniques-

i. Difficulty in

identifying causes &

effects because of their

vague description in

Natural language

specification .

ii. Error proneness based

on semantics of natural

language specification

Page 12: Gaur11428

Example – Send file Command

• Each column in the decision

table is converted into a test

case.

• Suppose file f, server r, and

user u are all correct

arguments, then the test case

derived from column 1 in the

decision table will be send and

the expected result is that file f

is successfully sent.

Page 13: Gaur11428

Problem in Myers’ approach -

Observation 1• Tracing back through an and node

whose output should be 0 all

combination of input leading to a 0

output must be enumerated ,except in

the case where one input is 0 and one

or more of others are 1.

1) If we consider cause c is set to 1 all

the combinations of causes a and b

leading to output 0 at node d should

be considered.

2) Cause c is set to 1 only one situation

where output d is set to zero is

considered(in fig 2.4(c) ).

Ambiguity occurred which misleads

the user.

Page 14: Gaur11428

Observation 2

• Decision table is different If

the syntax is different of the

Cause Effect Graph but the

semantic is same.

• Therefore with these rules,

the set of test cases obtained

from CEG will depend on

how effect e is formulated

thus the rules contradict a

reasonable requirement for

logical inconsistency.

Page 15: Gaur11428

Observation 3

• When building a Decision table , if often happens that some

entries are left blank meaning that irrelevant for presence/

absent of given effect.

• Don’t care conditions are unspecified.

Page 16: Gaur11428

Observation 4

• Missing in the description in

of the CEG Technique is

nothing is said about verifying

conformance of CEG to its

corresponding-natural

language specification may

lead to faulty and incomplete

test cases.

Page 17: Gaur11428

Problems in Myers’ approach –

Observation 5

• Myers’ does not consider when deriving test cases is the forcing of

effects to be absent. He concentrate only on their present.

Page 18: Gaur11428

Possible Solution to Drawbacks in

Myers’ Approach

• Cause Set – A cause set of an effect is the set of causes that can affect the

presence or absence of that effect.

• Path Sensitization Technique – In path sensitization Technique

combination of causes are derived from the CEG by sensitizing each

effect of the system to each cause in its corresponding cause set. The

combination of causes obtained can be used to derive actual test data

when the implementation of the system is tested

• Advantage of Path sensitization method:

• They all are algorithmic & they consist of Straightforward and

ambiguous rules for deriving a DT from a CEG.

Page 19: Gaur11428

Implementation of CEG into Decision-

Table Procedure for generating a decision table from Cause-effect graph.

1. input: A template containing causes C1,C2.....Cp, effects

E1,E2.....Eq then relationship and constraints.

2. output: A decision table DT containing N = p + q rows and M

columns, where M depends on the relationship between the

causes –effect as captured in the cause effect graph.

Procedure CEG_TO_DT:

• Step 1: Read causes and effects from template and for each of the

effect construct binary tree that specifies that effect in terms of

cause’s relationship.

• Step 2: Initialize DT to an empty decision table.

• Step 3: For each of the E, Create Decision Table EDTi as empty

decision table.

Page 20: Gaur11428

Step 4: Execute the following steps for i=1 to q

4.1 – Select the next effect to be processed, Let e = E

4.2 – Starting at e, traverse the effect tree created in previously step and

identify the causes C1, C2 ........etc that are there in tree. Identify all

possible combinations of these causes that lead e to be present. Make

sure that the combinations satisfy any constraints.

4.3 – Add all these possible entries into the decision t able EDTi .

Step 5: Do OR-Operation between all effects that gives all combination of

effects do following:

5.1 Select the decision tables EDTi for all effects that are present in this

combination.

5.2 Take all possible combination of entries of different tables. In this

combination if there is a cause that is there in two or more effect

decision table then take combination in which.

5.3 Enter all these entries into decision table that satisfy all constrain.

End of Procedure: CEG_TO_DT

Page 21: Gaur11428

Implementation Of Algorithm On

CasesWe consider the following set of requirements for implementing the

algorithm:

Requirements for Calculating Car Insurance Premiums:

• r1 For females less than 65 years of age, the premium is $500

• r2 For males less than 25 years of age, the premium is $3000

• r3 For males between 25 and 64 years of age, the premium is $1000

• r4 For anyone 65 years of age or more, the premium is $1500

There are two variables that will determine what the premium will be:

Gender and age. Therefore there are 5 distinct causes or input conditions:

Sex is either male or female, and age is either less than 25, between 25

and 64 inclusive or 65 or more. There are also 4 distinct effects or output

conditions: the premium is$500, $1000, $1500, or $3000.

Page 22: Gaur11428

Screenshots

Cause Effect Graph

Page 23: Gaur11428

Entry of Causes

Page 24: Gaur11428

Entry of Effects

Page 25: Gaur11428

Entry of Cases

Page 26: Gaur11428

CEG_TO_DT

Page 27: Gaur11428

Advantages of CEG Technique

• CEG technique is a useful testing technique to test the

implementation of the system by using test cases derived from

the natural language specification of the system.

• Technique is valid only for Natural language specification that

satisfies the customer intention.

Page 28: Gaur11428

Analysis of Previous and Implemented

Algorithm

• In existing algorithm for each effect binary tree isgenerated so complexity for finding all possiblecombination is less in comparison with previousalgorithm. Algorithm given is not generating allpossible test cases in all case whereas our algorithmgenerates all possible test cases in all the cases.

• Decision Table show in is generated by existingalgorithm which has all possible test cases where asDecision Table generated according to previousalgorithm has less number of cases.

Page 29: Gaur11428

Weighted Graph and Path Testing

• Weighted Graph : A graph is a weighted graph if a number

(weight) is assigned to each edge. Such weights might

represent, for example, costs, lengths or capacities, etc.

depending on the problem. The weight of the graph is the sum

of the weights given to all edges.

• Path Testing : Testing in which all paths in the program source

code are tested at least once.

Page 30: Gaur11428

Genetic Algorithm

A genetic algorithm (GA) is a heuristic used in computer

science to find an approximate solutions to combinatorial

optimization problems. Genetic algorithms are a particular

class of evolutionary algorithms that use techniques inspired

by evolutionary biology such as inheritance, mutation, natural

selection, and recombination (or crossover).

Page 31: Gaur11428

Advantage of GA in Software-

Testing

• One major advantage of GA is that other searches do not cover ,is

that of a false solution. A problem may have several solutions, some

are better than others. If another type of search finds that one path is

worth pursuing, and discards the other, it may be leading to a

solution which is not best, or even not to solution at all.

• GA have several individuals in its population, each one of which

could be a potential solution to a problem. Which means that it is

even possible for the search to find more than one solution.

Page 32: Gaur11428

Generating Effective Test Cases

with GA• The problem of test set generation is a typical optimization problem

in a combinatorial search space: we are looking for a minimal set oftest cases that are most likely to reveal faults presenting in a givenprogram.

• Representation: Each test case can be represented as a vector ofbinary or continuous values related to the inputs of the testedsoftware.

• Initialization: An initial test set can be generated randomly in thespace of possible input values.

• Genetic Operators: Selection, crossover, and mutation operators canbe adapted to representation of test cases for a specific program.

• Evaluation function: Test cases can be evaluated by their fault-exposing-potential using mutated versions of the original program.

Page 33: Gaur11428

Code with weighted Control Flow

Diagram0. gcd(int m, int n)

{

int r;

1. if(n>m) {

2. r = m;

3. m = n;

4. n = r;

}

5. r = m % n ;

6. while(r!=0) {

7. m = n ;

8. n = r ;

9. r = m % n;

10. }

11. return n;

12. }

Page 34: Gaur11428

Working of Algorithm for Control

Flow Graph

• Selection : selection for parents for reproduction is done accordingto probability distribution based on individual’s fitness values. Firstthe fitness value is calculated. Here X denotes the test data.

• F(x) : corresponding fitness value calculated for each data set, byadding the weights of the path followed by it in the CFG.

n

• F=∑ Wi (where Wi weight assigned to ith edge on the path under consideration)

i=1

• Probability of selection pj for each path j

• Pj = F(xi)/ ∑ F(xi) (where i=1 to n and n = initial population size)

k

• Calculate cumulative probability Ci = ∑ pj

j=1

Page 35: Gaur11428

• Ran: Random number generated for the test data

• Ns : Test data numbers that has cumulative probability just greater

than the corresponding random number.

• Mating pool : This column contains the number of times a test

data appears in the Ns column.

• Steps for carrying out cross over and mutation:

• Mutation: For each entry in the new data set, bit-wise random

number are generated. And for random number values less than

0.3, that corresponding bit is flipped to obtain a new data entry.

• Same procedure is carried out for the new data set obtained for

further crossover and mutation until we start getting better values

of the fitness function F(x).

Page 36: Gaur11428

Example 1: Initial population: (n, m) (15, 4), (5, 6), (6, 2), (4, 12)

Fitness function used: Summation of weights of path traversed by

a given input data in CFG For example (15, 4) will travel the path

0-1-2-3-4-5-6-7-8-9-6-7-8-9-6-10-11-12 and therefore its fitness

value is 108 Since the mating pool consists of only (15, 4) therefore

this is the test data that should be used for the testing of the code

during execution. This is because the mating pool depicts the

population that will mate in the next iteration. Here since the only

value in mating pool is (15, 4), this shows that no further

improvement in the fitness function value can be achieved with

further reproduction and mutation. Thus (15, 4) is the test data that

should be used as input for software testing.

Page 37: Gaur11428

Results

S.No X F(x) Pi Ci Ran Ns Mating

pool

1 (12,8) 76 0.228 0.228 0.934 4 0

2 (2,3) 106 0.317 0.545 0.474 2 2

3 (6,2) 44 0.132 0.677 0.374 2 1

4 (15,4) 108 0.323 1.000 0.618 3 1

Iteration 1: Table 7 and Table 8

S.No Ns Mating pool Crossover Mutation

1 4 (15,4)

11110100

(15,4)

11110100

(15,5)

11110101

2 2 (2,3)

00100011

(2,3)

00100011

(3,3)

00110011

3 2 (2,3)

00100011

(2,2)

00100010

(2,2)

00100010

4 3 (6,2)

01100010

(6,2)

01100010

(10,3)

10100011

Page 38: Gaur11428

Iteration 2: Table 9 and Table 10

S.No X F(x) Pi Ci Ran Ns Mating

pool

1 (15,5) 44 0.212 0.212 0.217 2 0

2 (3,3) 44 0.212 0.424 0.999 4 1

3 (2,2) 44 0.212 0.636 0.979 4 1

4 (10,3) 76 0.364 1.000 0.533 3 2

S.No Ns Mating pool Crossover Mutation

1 2 (3,3)

00110011

(3,2)

00110010

(5,10)

01011010

2 4 (10,3)

10100011

(10,3)

10100010

(9,10)

10010101

3 4 (10,3)

10100011

(10,3)

10100010

(11,6)

10110110

4 3 (2,2)

00100010

(2,3)

00100011

(2,2)

00100010

Page 39: Gaur11428

S.No X F(x) Pi Ci Ran Ns Mating

pool

1 (5,10) 74 0.223 0.223 0.934 4 0

2 (9,10) 106 0.319 0.542 0.474 2 2

3 (11,6) 108 0.325 0.867 0.374 2 1

4 (2,2) 44 0.133 1.000 0.618 3 1

S.No Ns Mating pool Crossover Mutation

1 4 (2,2)

00100010

(2,2)

00100010

(4,3)

00100011

2 2 (9,10)

10011010

(9,10)

10011010

(7,12)

01111100

3 2 (9,10)

10011010

(9,10)

10011010

(13,10)

11011010

4 3 (11,6)

10110110

(11,6)

10110110

(2,6)

00100110

Iteration 3: Table 11 and Table 12

Page 40: Gaur11428

S.No X F(x) Pi Ci Ran Ns Mating

pool

1 (4,3) 76 0.178 0.178 0.098 1 1

2 (7,12) 170 0.399 0.577 0.275 2 3

3 (13,10) 106 0.249 0.826 0.325 2 0

4 (2,6) 74 0.174 1.000 0.487 2 0

Iteration 4: Table 13

Result : From the Table 13 the optimized path 170 because its rank is high which is 3.

Page 41: Gaur11428

Conclusion• The goal is to validate the informal specification is well. We

developed a tool to derive the decision table and the customer-

directed scenarios automatically from a given Cause-Effect Graph

specification. The CEG is input in a text format; our tool gives

outputs the decision table and the customer directed scenarios.

• we applied some optimization approach for more effective software

Testing. Genetic algorithms are often used for optimization

problems in which the evolution of a population is a search for a

satisfactory solution given a set of constraints.

• We have demonstrated that it is possible to apply Genetic Algorithm

techniques for finding the most critical paths for improving software

testing efficiency. The Genetic Algorithms also outperforms the

exhaustive search and local search techniques.

Page 42: Gaur11428

References[1] Aditya P mathur, “Foundation of Software Testing”, 1st edition Pearson Education 2008.

[2] Alander, J.T., Mantere, T., and Turunen, P, “Genetic Algorithm Based Software Testing,”

http://citeseer.ist.psu.edu/40769.html, 1997.

[3] Berndt, D.J., Fisher, J., Johnson, L., Pinglikar, J., and Watkins, A., “High Volume

Software Testing with Genetic Algorithms,” In Proceedings of the Thirty-Eighth Hawaii

International Conference on System Sciences (HICSS-38), Hawaii, January 2005.

[4] Cai Ferriday, “A Review paper on Decision Table Based Testing”, 2007

[5] Goldberg, D.E, “Genetic Algorithms: in Search, Optimization & Machine Learning,”

Addison Wesley, MA. 1989.

[6] Khenaidoo Nursimulu, Robert L. Probert,“Cause-Effect Graphing Analysis and

validation of Requirements”, CASCON '95 Proceedings of the 1995 conference of the

Centre for Advanced Studies on Collaborative research.

Page 43: Gaur11428

[7] Kuo-Chang Tai 1, Amit Paradkar 2, Husn Kang Su and Mladen A. Vouk, “Fault

BasedTest Generation for Cause-Effect Graphs”, CASCON '93 Proceedings of the 1993

conference of the Centre for Advanced Studies on Collaborative research.

[8] Myers, G.L., “The Art of Software Testing ”,Wiley-Interscience , New-York.

[9] Praveen Ranjan Srivastava, Parshad Patel, Siddharth Chatrola “Converting Cause Effect

Graph to Decision Table.” Vol. 2, No.4, October 2009

[10] Praveen Ranjan Srivastava, Tai-hoon Kim, “Application of Genetic Algorithm in

software Testing” International Journal of Software Engineering and Its Applications

Vol. 3, No.4, October 2009

[11] Reeves, C. R.: Using Genetic Algorithms with Small Populations, Proc. of the Fifth

International Conference on Genetic Algorithms and Their Applications, Morgan

Kaufmann, (1993) 92-99.

Page 44: Gaur11428

[12] Rex Black,“Advanced Software Test Design Techniques, Decision Tables and

cause-Effect Graphs”, Advanced Software Testing: Vol. 1, 2009

[13] Schroeder P. J., and Korel, B. “Black-Box Test Reduction Using Input-Output

Analysis”. In Proc. of ISSTA '00 (2000),173-177.

[14] Vouk, M.A. and R.E. Coyle (1989), “BGG: A Testing Coverage Tool,” In

Proceedings of 7th Annual Pacific Northwest Software Quality Conference,

Lawrence and Craig, Inc., Portland, OR, pp. 212–233.

[15] The Westfall Team, “Cause-Effect Graphing by Theresa Hunt”, 2007.

Page 45: Gaur11428

Thank You.