A Testing Approach through Ant Colony Optimization - Semantic Scholar

0 downloads 0 Views 439KB Size Report
Software Coverage : A Testing Approach through Ant. Colony Optimization. Bhuvnesh Sharma, Isha Girdhar, Monika Taneja, Pooja Basia, Sangeetha Vadla,.
Software Coverage : A Testing Approach through Ant Colony Optimization Bhuvnesh Sharma, Isha Girdhar, Monika Taneja, Pooja Basia, Sangeetha Vadla, and Praveen Ranjan Srivastava Birla Institute of Technology and Science, Pilani Campus, India {bhuvnesh.bits,ishagirdhar,monicks1,pooja.basia,san3003.v, praveenrsrivastava}@gmail.com

Abstract. Software Testing is one of the most important parts of the software development lifecycle. Testing effectiveness can be achieved by the State Transition Testing (STT) and path testing which is commonly used for carrying out functional and structural testing of software systems. The tester is required to test all possible transitions and paths in the system under built. Aim of the current paper is to present an algorithm for generation of test sequences for state transitions of the system as well as path generation for CFG of the software code using the basic property and behavior of the ants. This novel approach tries to find out all the effective (or can say optimal) paths and test sequences by applying ant colony optimization (ACO) principle using some set of rules. This algorithm tries to give maximum software coverage with minimal redundancy. Keywords: Software Testing, Ant Colony Optimization (ACO), Genetic Algorithm (GA), State Transition Testing (STT), Test Data, Test Sequence, Control Flow Graph (CFG).

1

Introduction

Software Engineering [1] is an engineering discipline which focuses on developing high-quality software systems which are cost effective. It is a profession where in designing, implementation, and modifications of software are involved. Software Development Life Cycle [1] is a process of developing a system which involves different steps like investigation, analysis, design, implementation and maintenance. Through software testing an organization can gain consumers’ confidence towards the system [1]. Software testing is a labour intensive and very expensive task. It accounts almost 50 % of software development life cycle [2] [3]. Many testing tools and methodologies have been emerging in the field of software testing. Code coverage analysis is one such methodology, which helps in discovering the instructions in a software program that have been executed during a test run and helps in discovering how the testing can be further improved to cover more number of instructions during testing of a software program [2]. This paper proposes an algorithm with tool, named ESCov (Efficient Software COVerage), which uses an ACO technique [4] to generate the optimal paths, to ensure B.K. Panigrahi et al. (Eds.): SEMCCO 2011, Part I, LNCS 7076, pp. 618–625, 2011. © Springer-Verlag Berlin Heidelberg 2011

Software Coverage : A Testing Approach through Ant Colony Optimization

619

maximum coverage of structural as well as behavioral testing with minimal redundancy. The work is divided into two phases. In the first phase, maximum code coverage will be achieved via functional testing. For this optimized test sequences are generated by applying the ESCov, on the directed tree graph generated from the state chart diagram of the system. After that for the obtained test sequences test data is generated manually while in the second phase, the same ESCov is applied on the CFG of the software code under test. Finally, test data is applied on the generated test sequences obtained in the second phase to validate the maximum coverage.

2

Background Work

Software testing is done with many approaches such as Particle Swarm Optimization, Genetic Algorithm, and Ant Colony Optimization etc. in which ACO is one of the effective approaches. A hybrid approach using ACO and a markov software usage model [5] can produce some better results for deriving a set of independent test paths for a software system. McMinn [6] discussed application of ACO for finding sequences of transitional statements in generating test data under evolutionary testing. Another approach for state based testing using an ACO is represented [7] in which only states are considered and not complete transitions. Many AI based techniques like Neural Networks, the black-box data processing structure is very complex and it provides a slow convergence speed [8]. Although the search in genetic algorithms is not exhaustive, the algorithm fails to find a global optimum of the fitness if get stuck in local extreme [9]. Ant colony optimization is inspired by foraging behaviors of ant colonies, and target discrete optimization problem [4]. Real ants coordinate with each other by dropping and sensing a chemical level known as pheromone on the paths. Selection of path by ants depends on stochastic or probability theory. The main idea is the self organizing principle, which allows the highly coordinated behavior of real ants can be applied with the artificial agents, which collaborate to solve the complex computational problems. In the next section this paper proposed solution regarding total software coverage.

3

Proposed Algorithm

Purpose of the proposed Algorithm is providing the optimal path coverage for state transition diagram as well as CFG of the software under test. Selection of path depends upon the probability of the path. Ant will choose the path where the probability value is high. The probability value of path depends upon: probability value calculated by ant at each node for which it has pheromone value (τij), which helps other ants to make decision in the future, and heuristic information (ηij) of the path, which indicates the visibility of a path for an ant at the current vertex. In some cases if there are equal probabilities the ant will select any feasible path randomly. The architecture of the proposal is depicted in Figure 1.

620

B. Sharma et al.

Fig. 1. Architecture of ESCov

In ESCov ant will calculate the probability based on the pheromone value and heuristic value. After the selection of a particular path ant update the pheromone level as well as heuristic value. Pheromone level is increased according to last pheromone level but heuristic value is decreased according to the last heuristic value. An ant p at a vertex ‘i’ and another vertex ‘j’ which is directly connected to “i”, it means there is a path between the vertices ‘i’ and ‘j’ i.e. (ij). The use of variables and sets used in the ESCov is given below: 1. Edge set: E = {(a, b), ()…} represents the set of all the edge(s) present in the graph. 2. Vertex set: V = {a, b…} represents the set of all the nodes present in the graph. 3. Track set: T = {{a, b…}, {a, c…}…} represents the set of traversed path(s) in the graph. 4. Pheromone value: τ = τij (p) represents the pheromone level on the edge (i, j) from current vertex ‘i’ to next vertex ‘j’ for ant ‘p’. The pheromone level is updated after the particular edge traversed. This pheromone helps other ants to make decision in future. 5. Heuristic value: η = ηij (p) indicates the desirability of a path for an ant at current vertex ‘i’ to vertex ‘j’ for ant ‘p’. 6. Probability: Selection of path depends on probabilistic value of path because it is inspired by the ant behavior. Probability value of the path depends upon pheromone value τij (p) and heuristic information ηij (p) of path for ant p. There are α, β two more parameter which used to calculate the probability of a path. These parameters α and β control the desirability versus visibility. α and β are associated with pheromone and heuristic value of the paths respectively. In the ESCov, values taken for α and β is 1. An algorithm is proposed for generating optimal paths for state transition diagram and CFG as well.

Software Coverage : A Testing Approach through Ant Colony Optimization

621

Algorithm for ant p Step 1: Initialize all parameter 1.1 Set heuristic Value (η): for every edge initialize heuristic value η =1. 1.2 Set pheromone level (τ): for every edge initialize pheromone value τ =1. 1.3 α=1, β= 1 Step 2: Run the algorithm

2.3.4.4 IF outdegree > 1 AND

2.1 WHILE indegree of end node(s) is not

2.3.4.6 ELSE IF indegree = 1 AND

(no of end nodes) >1 THEN Delete the edge from E 2.3.4.5 ELSE IF indegree > 1 THEN Delete the incoming edge from E outdegree = 1 THEN

empty DO

Delete the incoming and outgoing edges

2.2 Set current = start node 2.3 LOOP Evaluation at vertex i

from E 2.3.4.7 END IF BREAK (LOOP)

2.3.1 Update the Track Set– Push the current vertex i into the track set T

2.3.5 ELSE

2.3.2 At the ith node Get next nodes

2.3.5.1 Calculate the probability of all

(check if there is a ‘self loop’) 2.3.3 IF (there is a ‘self loop’) THEN

possible edges

[τ ] × [η ] α

Pij =

2.3.3.1 Select that edge regardless of the

ij

−β

ij

α β ∑[[τ ] × [η ] ] k



ik

∀k ∈ feasibleset(F( p))

ik

1

probability 2.3.3.2 Move to the selected node.

2.3.5.2 Select the edge with max probability.

2.3.3.3 Enter it in track set T.

2.3.5.3 Select the node.

2.3.3.4 Delete the edge from E.

2.3.5.4

(check if an edge is there to ‘End node’.)

Update

pheromone

level

and

desirability factor of edge i,j as

2.3.4 ELSE IF (there is a direct edge to ‘end

New τij = 2 * curr pheromone level of that

node’) THEN

edge

2.3.4.1 Select that edge regardless of the

New ηij = curr heuristic value of that edge / 4

probability

2.3.5.5 SET current = selected node

2.3.4.2 Select the node

2.4 IF end node is not reached continue

2.3.4.3 Enter it in track set T

LOOP at Step 2.3 2.5 End While

4

Demonstration of Proposed Algorithm

The example work is divided into two phases: The basis of software requirement model, a state transition model constructed for a system, the algorithm is applied on directed graph under state transition diagram of the system in first phase and in second phase a CFG of the program code should be considered as input. In both the cases, an ant start from start node which would be specified by the user and it can generate a sequence of test cases. Test sequence depends upon the feasibility of path from the current vertex to other vertices and accordingly decision for further proceeding, and in the end, it give the optimal test sequences for the module under test. Here optimal means maximum coverage with minimal redundancy.

622

B. Sharma et al.

For the program taken under test, the state transition diagram and corressponding directed graph are given as below(for example) in Figure 2 and 3 respectively.

Fig. 2. The state transition diagram

Fig. 3. The directed graph for the STD

The ESCov is applied on given diagram and the test sequences obtained alongwith the values calculated at each node by the ants is given in tables (for respective ants). At node 0 (starting node) there is only one outgoing edge to node 1. Ant move to the next node since there is no need of selection. At node 1 there are three outgoing edges (1, 1) self loop, (1, 2) and (1, 3). The ant calculates the probability value using the probability formula for each edge. All edges have same probability vaue of 0.33. So ant select any edge randomly say it chooses (1,1), update the pheromone level and heuristic value and move to the node 1. Now edge (1, 1) be blocked according to the algorithm. Now at node 1 ant is left with only two options (1, 2) and (1,3). Since 2 is the end node and the algorithm makes the ant to move to the end node if it is directly connected to the current node, ant chooses (1, 2). Since the end node is encountered, the first ant stops, and the path can be calculated by traversing the edges and nodes covered by the ant. Ant 1 take the path mentioned in the table from the start node to the end node.

Similarly, the second ant generate a path from the starting node to the end node mentioned in the table

Software Coverage : A Testing Approach through Ant Colony Optimization

623

Test sequences generated by the two ants for the state transition diagram of the program under test are: Path 1: 0112

&

Path 2: 0131345

Here the ants have generated two test sequences and covered all nodes as well as edges so the coverage is 100%. Now the algorithm be applied to the CFG of the code and optimal paths would be generated. For the code under test (for example), the CFG is given in Figure 4. The path sequences obtained by applying the ESCov on the CFG are given in the tables given for individual ants. The optimal paths generated by ESCov are Path1:01234 Path2:01111213 Path 3:0123563567810 Path4:01111214 Path5: 0123563567910

Fig. 4. CFG for source code

Illustration of path table for Ant 3 is shown in tabular representation as below (for example):

624

B. Sharma et al.

Here the ants have generated five paths and covered all nodes as well as edges so the coverage is 100% with minimal redundancy since no path is repeated.

5

Analysis

The main proposed advantage of the algorithm is the maximum coverage with minimal repetition. It is tried to be achieved by avoiding self loops to be executed repeatedly reducing the redundancy. The time complexity in best case is O (n*log n), but the same in average or worst case is O (n2). There is a constraint in the ESCov in case of functional testing; it only captures single transition in between two states. If there are more than one transition in between two states, then only one is considered and rest are left untraversed.

6

Experimentation, Results and Discussion

The ESCov, to prove its essence, is compared with predefined tools (say Q) for functional coverage [11] and for structural coverage (PPTACO) [10]. Functional This paper used a class management system state machine diagram [11] as case study on which it gave 4 possible paths for transitions given in table as reported in [11]. The ESCov is then applied on the state chart diagram of the same case study which now produces 3 independent paths covering all the states and hence gives total coverage. Therefore, it shows the ESCov provides minimal number of repetitions producing maximum coverage. Structural The PPTACO tool along with path generation also calculates strength [10] for prioritizing the paths to be covered. But as shown the path generation algorithm using ACO has repetition in it but ESCov provides the same coverage with minimum repetition.

The above graph shows the difference that the number of iterations increases if there is more scope of coverage. Every iteration gives a different path in the ESCov minimizing the redundancy.

Software Coverage : A Testing Approach through Ant Colony Optimization

7

625

Conclusion

This paper proposes a model and tool named ‘ESCov’ for test sequence generation for state based testing and optimal path generation for structural testing using ant colony optimization. The result that is produced by applying proposed method is very encouraging. To model the system state chart diagram and CFG are taken and the algorithm is applied over them. After successful execution of algorithm, it shows path sequence, which gives maximum coverage and minimum redundancy. This algorithm may be very useful and helpful for the testers in the software industry. A number of extensions and applications of this model may be possible by using the different metaheuristic techniques.

References [1] [2] [3] [4] [5]

[6]

[7]

[8] [9] [10]

[11]

Sommerville, I.: Software Engineering, 8th edn. Pearson Edition (2009) Mathur, A.P.: Foundation of Software Testing, 1st edn. Pearson Education (2007) Myers, G.: The Art of Software Testing, 2nd edn., p. 234. John Wiley & Son. Inc. (2004) Dorigoa, M., Stutzle, T.: Ant colony optimization, The Knowledge Engineering Review, vol. 20, pp. 92–93. Cambridge University Press, New York (2005) Doerner, K., Gutjahr, W.J.: Extracting Test Sequences from a Markov Software Usage Model by ACO. In: Cantú-Paz, E., Foster, J.A., Deb, K., Davis, L., Roy, R., O’Reilly, U.-M., Beyer, H.-G., Kendall, G., Wilson, S.W., Harman, M., Wegener, J., Dasgupta, D., Potter, M.A., Schultz, A., Dowsland, K.A., Jonoska, N., Miller, J., Standish, R.K. (eds.) GECCO 2003. LNCS, vol. 2724, pp. 2465–2476. Springer, Heidelberg (2003) McMinn, P., Holcombe, M.: The State Problem for Evolutionary Testing. In: Cantú-Paz, E., Foster, J.A., Deb, K., Davis, L., Roy, R., O’Reilly, U.-M., Beyer, H.-G., Kendall, G., Wilson, S.W., Harman, M., Wegener, J., Dasgupta, D., Potter, M.A., Schultz, A., Dowsland, K.A., Jonoska, N., Miller, J., Standish, R.K. (eds.) GECCO 2003. LNCS, vol. 2724, pp. 2488–2500. Springer, Heidelberg (2003) Li, H., Lam, C.P.: An Ant Colony Optimization Approach to Test Sequence Generation for State based Software Testing. In: Proceedings of the Fifth International Conference on Quality Software (QSIC 2005), pp. 255–264 (2005) Briand, L.C.: On the many ways Software Engineering can benefit from Knowledge Engineering. In: Proc. 14th SEKE, Italy, pp. 3–6 (2002) Pedrycz, W., Peters, J.F.: Computational Intelligence in Software Engineering. World Scientific Publishers (1998) Srivastava, P.R., Baby, K.M.: An Approach of Optimal Path Generation using Ant Colony Optimization, pp. 1–6. IEEE-TENCON, Singapore (2009) ISBN-978-1-42444546-2 Doungsa-ard, C., Dahal, K., Hossain, A., Suwannasart, T.: An Improved Automatic Test Data Generation from UML State Machine Diagram. In: ICSEA (2007)