Professional Documents
Culture Documents
Regular Paper
a r t i c l e i n f o a b s t r a c t
Article history: Software testing is an important but complex part of software development life cycle. The optimization of
Received 21 December 2011 the software testing process is a major challenge, and the generation of the independent test paths remains
Received in revised form unsatisfactory. In this paper, we present an approach based on metaheuristic firefly algorithm to generate
5 August 2012
optimal test paths. In order to optimize the test case paths, we use a modified firefly algorithm by defining
Accepted 15 August 2012
appropriate objective function and introducing guidance matrix in traversing the graph. Our simulations and
Available online 25 September 2012
comparison show that the test paths generated are critical and optimal paths.
Keywords: & 2012 Elsevier B.V. All rights reserved.
Firefly algorithm
State transition diagram
Objective Function
Cyclometic complexity
Control flow graph
2210-6502/$ - see front matter & 2012 Elsevier B.V. All rights reserved.
http://dx.doi.org/10.1016/j.swevo.2012.08.003
P.R. Srivatsava et al. / Swarm and Evolutionary Computation 8 (2013) 44–53 45
were achieved. But node redundancy was still an issue. In another there are three assumptions in firefly algorithm:
approach, optimal software test data produced by artificial bee
colony (ABC) [17] seemed to work well for programs of small 1. All fireflies are unisexual and every firefly attracts/gets attracted
sizes. However, as the size of software increases, finding paths to every other firefly.
and test data becomes more difficult because this ABC method 2. The attractiveness of a firefly is directly proportional to the
may be trapped in local search space and the number of iterations brightness of the firefly. (The brightness decreases as the
is quite high. On the other hand, the approach for test data distance traveled increases.)
generation using particle swarm optimization (PSO) did not have 3. They move randomly if they do not find a more attractive
much discussion for path generation and coverage [18]. Test path firefly in adjacent regions [19].
generation using ant colony optimization (ACO) was attempted
in [10], but there was an issue of transition repetition in the In the above firefly algorithm, the light intensity I(r) decrease
sequences generated by that method. as the distance between two fireflies increases. Intensity varies
In order to generate more complete software coverage, we with distance (r)
have to find an optimal test path, which is still a challenging task.
IðrÞ ¼ Io exp½gr, ð1Þ
In this paper, we try to explore the possibility for generating
optimal and minimal test cases with full coverage by using a where g is the light absorption coefficient, which can often be taken
recently developed Firefly Algorithm (FA) [19]. FA [19] was as 1. FA has been applied in spatial fields with different dimensions
developed by Xin-She Yang, inspired by the flashing behavior of with promising efficiency and superiority over other algorithms.
fireflies. Mechanisms of firefly communication via bioluminescent FA is a metaheuristic algorithm, which assumes that a solution of an
flashes and their synchronization have been imitated effectively optimization problem is encoded as the location of the agent/firefly,
in various techniques of wireless networks design [20], dynamic while the objective function is encoded as the light intensity. In
market pricing [21], mobile robotics [22], economic dispatch FA, there are two important issues that make the algorithm success-
problem [32],and structural optimization problems [33]. ful: (1) variations in light intensity, and (2) the right formulation of
In this paper, we use FA to obtain the optimal set of test attractiveness, which is determined by brightness function, which in
sequence generation using state transition diagram (STD) [23] turn is associated with the objective function. Attractiveness of a
and control flow graphs (CFG). firefly in the search space is directly proportional to the objective
In software engineering, the so-called state transition diagram function value of the firefly.
can be generated from the requirements or specifications of the
software to be developed. The state transition diagram (STD) [24] 2.2. Objective function
indicates how the system behaves because of external events. To
accomplish this, the STD represents the various modes of beha- The objective function of an optimization problem defines the
viors (called states) of the system, and the manner in which objective to be maximized or minimized in the search space and
transitions are made from state to state. We will show that FA domain of design variables [19,26]. A well-formulated objective
can generate an optimal set of paths from the state transition function will help the search process, while a poorly formulated
diagram. objective function may lead to inappropriate or wrong solutions.
The approaches by Srivastava and Baby [25] and Lam and Li [9] A well-defined objective function reduce the search effort tremen-
used ant colony optimization to find test paths, but they still have dously. Here as the objective function determines the attractiveness/
redundancies in the paths generated. Redundancy in generation brightness of firefly’s in a state or a node of a graph, where each state
of test paths requires more transitions to cover the graph and thus or node’s objective function value can be different, derivations of
more testing efforts are needed. objective function should use key properties of a STD or a CFG.
This paper proposes a FA-based method of optimal test sequence In the standard FA, light intensity and variations in brightness play
generation for state-based and control flow graph. The proposed FA a crucial role in encoding the objective function, while designing a
can generate an optimal set of paths without redundancy. This is a good objective function is important to a good problem formulation
significant advantage over other approaches. to be solved by any algorithms. In this paper, the proposed algorithm
The paper is organized as follows. In Section 2, we will describe can adapt and extend the above two entities by considering cyclo-
the fundamentals of Firefly Algorithm and appropriate formulation metic complexity [28], and graph traversal, as discussed in more
of objective function [26]. In Section 3, we provide an overview detail later. We will apply the proposed algorithm into software
of proposed method using firefly algorithm and other relevant testing domain. In addition, the intensity factor can be determined by
characteristics. In Section 4, we show the proposed algorithm by using cyclometic complexity of the graph’s nodes and variation of
examples. Then, in Section 5, we apply that the proposed approach attractiveness can be implemented by having the absorption coeffi-
to path generation and provide a brief comparison with other cient at every edge to be discussed in Section 3.
approaches such ACO in the literature. Finally, in Section 6, we Therefore, our proposed algorithm uses the following entities
draw some conclusions and discuss topics for future research. in designing the objective function.
1. Cyclometic complexity.
2. Random function.
2. Related concepts
Cyclometic complexity (CC) [28] is a software metric, which is
2.1. Firefly algorithm [19] used to indicate the complexity of a program. On testing strategy
of McCabe Basic Path Testing, the number of independent paths
The flashing light of fireflies is an amazing sight in the summer generated is equal to the Cyclometic complexity of the graph.
sky in the tropical and temperate regions. The pattern of rhythmic Let M be an upper bound for the number of test cases that are
flashes is often unique for a particular species. The flashing light necessary to achieve branch coverage, and N be a lower bound
can be formulated in such a way that it is associated with the for number of test cases to achieve path coverage. CC can be
objective function to be optimized, which makes it possible to defined as:
formulate new optimization algorithms. According to Yang [19], Cyclometic Complexity [CC] Mo ¼CC o ¼N.
46 P.R. Srivatsava et al. / Swarm and Evolutionary Computation 8 (2013) 44–53
Cyclometic complexity is also known as V(G), where V refers given software under test. The Data Flow Diagram (DFD) [9] of the
to the Cyclometic number in graph theory, and G indicates that algorithm is shown in the Fig. 1.
the complexity is a function of the graph. In a strongly connected The proposed algorithm starts with the objective function for
directed graph G, the Cyclometic number can be defined as V the STD provided. Fireflies/solutions are generated at each node
(G) ¼E–Nþ2, where E is the number of edges in the control flow with different intensity of brightness at each node using cyclo-
graph (CFG), and N is the number of nodes. metic complexity [28] and a random function [19]. Every node
Control flow graphs (CFG) represent the control flow of has been made to have a guidance factor, as discussed later,
programs [27]. It has nodes connected by edges and has one or in guiding the fireflies. Fireflies can traverse the graph by the
more entry or exit points. Nodes are expressed as labeled circles, guidance factor to record the optimal paths.
representing one or more statements. Edges are directed arrows If an optimal path can be achieved, the fireflies [19] essentially
that represent the control flow of the program. CFG is widely used reverse each independent (generated form optimal path) path,
in the analysis of software test cases. starting from the start node of the graph. As fireflies traverse
Random function [29]: A random function or a Randomiza- through the path, they undergo changes in their brightness which
tion function is a vector with random variables defined according also varies due to variations in absorption coefficient of edges and
to the dimensions in which the algorithm is used. Randomization simultaneously get attracted to brighter fireflies of other nodes.
along with scaling parameters is employed to differentiate the The proposed algorithm extends the basic FA algorithms assump-
dimensions they travel. tions described in Section 2 of the paper with the following
The above elements can be used to formulate the objective assumptions:
function with cyclometic complexity as the main element of design
in the proposed approach. The attributes such as cyclometic Assumption 1. Fireflies tend to move towards a brighter firefly as
complexity and the random function act as local variables of soft- a process of attraction.
ware testing in determining the objective function. In the following In Yang’s original firefly algorithm [19,29], the distance tra-
sections, we will describe the main elements of the proposed veled by a firefly is measured by a Cartesian distance/Euclidean
approach and the formulation and derivation of the proper objective distance or time lag between processes/proximity of vertices in a
function. hyperspace/job scheduling/social networking. To date FA has
been applied in many areas, however, it has not been applied in
software testing. Thus, in our proposed modification of FA, we
3. FA-based approach have to redefine the distance as described below. In contrast to
the Cartesian distance
vffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
The proposed approach (Fig. 1) can generate optimal test u d
u X
sequences that will cover all the transitions. The approach uses ½r ij ¼ X i 2X j ¼ t ðX ik X jk Þ2 ð2Þ
the Firefly algorithm, developed by Yang [19]. This approach can k¼1
provide the optimal set of paths from the STD and CFG [28] of the
where i, j correspond to the fireflies at Xi and Xj, and Xik is the kth
component of the spatial coordinate of the firefly, while in our
proposed algorithm, we define the distance traveled by a firefly in
a graph as
X
r i,j ¼ Distance between node=state i and j ¼ eij ¼ sum of edges
where r is the distance between node i and j and eij is the sum of
edges between i and j. Assumed an ideal edge weight eij ¼1 for
every edge in CFG/STD because it is conventionally assumed the
tested distance is unity between the nodes.
calculating the mean brightness at the end node. The path with detailed formulation of the objective function and random function
the highest mean brightness can be taken as the highest priority and the definition of Adjacency matrix and Guidance factor/
path. Guidance matrix.
Now we describe the entities of the proposed algorithm in Objective function or fitness function: The objective function
more detail, though the basic design of the objective function and f(x) corresponds the goal, which associates each solution of the
random function are described in Section 2. Now we discuss the search space with a real value that describes the quality or fitness
of the solution [13]. Firefly algorithm utilizes a relative fitness generation of software test paths, and we will demonstrate this
association to rank the individual in the population. In this paper, by an example in Section 4 below using an OFTSG tool in which
we use a modified objective function in the following form: we have implemented our test algorithm.
All visited nodes are replaced with zero in the matrix after
fireflies can be calculated to prioritize the path. Fig. 3 below the first iteration. The next iteration generates the rest of
shows a sample STD built to generate a test case. the paths.
For iteration 2. Table. 3 below depicts the status of adjacency
State-diagram:
matrix after visited nodes are removed from the matrix.
Tool Used: Eclipse[IDE] [Unimod – Plug-in].
Unimod plug-in has been used for the generation of state-
based diagrams.
Export as: The Generated State diagram can be exported as
XML.
OFTSG TOOL: OFTSG is the implemented tool of the proposed
algorithm.
Methods/Modules
Read ( ) -XML parsing.
–It reads the XML file, parses it and extracts nodes and edges
to file.
Draw ( )
–It reads the file generated by read function and generates
the following elements:
The mumber of nodes read from XML file is 8.
The mumber of edges read from XML file is 11
Evaluated Cyclometic Complexity of STD: 5
Calculating Cyclometic Complexity of Each Node:
CC at S1:5
CC at S2:5
CC at S3:4
CC at S4:4
CC at S5:3
CC at S6:2
CC at S7:1
CC at S8:100[END node affinity]
Adjacency Matrix: Adjacency matrix
Out degrees:
Out degree for node 3 is 2 a decision state
Out degree for node 5 is 2 a decision state
Out degree for node 6 is 2 a decision state
Out degree for node 7 is 2 a decision state Fig. 4. Pseudo-code for adjacency matrix.
50 P.R. Srivatsava et al. / Swarm and Evolutionary Computation 8 (2013) 44–53
Table 3
Adjacency matrix after 1st iteration. At S2: CC¼ 5;
F(x1j)¼100/ (5nr and()); here r and ()¼[6.9 y.6.1]
States 1 2 3 4 5 6 7 8
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
3 0 0 0 1 0 0 0 0 2.9 2.94 2.99 3.03 3.28 3.08
4 0 0 0 0 0 1 0 0 3.13 3.17 3.23
5 0 0 0 0 1 0 0 0
6 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 1
8 0 0 0 0 0 0 0 0
At S3: CC¼ 4
F(x1j)¼100/ (4nr and ()); here r and ()¼[5.9y.5.1]
Table 4
Optimal test sequences generated by OFTSG. 3.38 3.44 3.5 3.57 3.63 3.7
3.77 3.84 3.91 4
Path 1: 1,2,3,5,6,7,6,8
Path 2: 3,4,6
Path 3: 5,5
Path 4: 7,8
At S4: CC¼ 4
F(x1j)¼100/ (4nr and ()); here r and ()¼[4.9 y.4.1]
Once all independent paths are double-checked, the paths are At S6: CC¼ 2
then used for software testing. Since testing depends on fixed F(x1j)¼100/(4nr and ()); here r and ()¼[2.9y.2.1]
resources, path prioritization is needed.
Test path prioritization involves scheduling over test cases in
an ordered manner so as to improve the performance of regres-
sion testing. Path prioritization is to find the critical paths that 11.4 11.9 12.34 12.82 13.12 13.33
a tester might want to test and/or prioritize. In the current test 13.88 14.49 15.15 15.87
case, ten fireflies are used at each state/node and they can
traverse the independent paths listed above. In the following
tables, each box corresponds a firefly with a brightness value At S7: CC¼ 1
at each state/node linked with the cyclometic complexity and F(x1j)¼100/(4nr and ()); here r and ()¼[1.9y.1.1]
random function.
Firefly generation: For all the test cases in the paper, ten
fireflies are deployed at every node as inputs.
The following tables represent fireflies with brightness value 26.3 27.7 29.4 31.25 33.33 35.71
at every state: 38.46 41.66 45.66 50
At S1: CC ¼5;
F(x1j)¼100/ (5nr and ()); here r and ()¼[7.9 y.7.1]
Sample calculation F(x11) ¼100/(5n7.9) ¼2.53 After the generation of fireflies at each state, the mean of the
Similarly, we have F(x12) F(x13) yy.. fireflies’ brightness is calculated at every end state of a path.
Here F(x1i) ¼ brightness function of firefly i at S1 Mean calculation:
Path 1:1, 2,3,5,6,7,6,8
At node 8:
Similarly for
Path 2: 1, 2, 3,5,5,6,7,6,8,
we have the mean of brightness of fireflies from Node 1 to Table 7
Test-sequence generated by Srivastava’s [10] algorithm.
Node 8 covering 1-2-3-5-5-6-7-6-8. So the
arithmetic mean of brightness¼8.79. Paths Nodes
Path 4: 1,2,3,4,6,7,8
At node 8:
The mean of brightness of fireflies from Node 1 to Node
8 covering 1-2-3-4-6-7-8
After the calculation of all means, the path with the highest
mean value is prioritized as a critical path. In general, the
path, which has a higher number of predicate nodes, is
assigned with high priority as shown in Table 5.
1-2-3 S1
Table 5 4 S2
Path prioritization. 5 S3
6 S4
Priority Paths Mean 7-8-9 S5
1 Path3: 1,2,3,5,6,7,8 9.33
10 S6
2 Path 1: 1,2,3,5,6,7,6,8 9.27 11 S7
3 Path 2: 1,2,3,5,5,6,7,6,8 8.79 12 S8
4 Path 4: 1,2,3,4,6,7,8 8.75 13 29
52 P.R. Srivatsava et al. / Swarm and Evolutionary Computation 8 (2013) 44–53
Table 8 Table 9
Optimal test sequence paths generated by OFTSG. Test cases for comparing FA and ACO.
In addition, our new approach produces zero repetition of International Conference (IEEE) on Natural Computation, ICNC, vol. 1, 2008,
paths, and thus makes it more efficient than other algorithms. pp. 566–570.
[14] Praveen Ranjan Srivastava, Vinod Ramachandran, Manish KumarGourab
Talukder, Vivek Tiwari, Prateek Sharma, Generation of test data using meta
heuristics approach, in: Proceedings of the TENCON 2008 - 2008 IEEE Region
6. Conclusion 10 Conference, India, 2008, pp. 1–6.
[15] W Pedrycz, J.F Peters, Computational Intelligence in Software Engineering,
By using a good combination of firefly algorithm and graph World Scientific Publishers Singapore, 1998.
[16] Praveen Ranjan Srivastava, Monica Chis, Suash Deb, Xin-She Yang, Path
reduction, we have extended the standard firefly algorithm to
optimization for software testing: an intelligent approach using cuckoo
generate optimal discrete and independent paths for software search, in: Proceedings of the 4th Indian International Conference on
testing. The proposed approach is the first of kind in the field Artificial Intelligence, IICAI 2011, Bangalore, India, pp. 725–732, ISBN:
of software testing, which minimizes the number of test cases 978-0-9727412-8-6.
[17] Soma SekharaBabu Lam, Raju M.L. Hari Prasad, M. Uday Kiran, Ch Swaraj,
by optimizing the test paths for test cases. Graph reduction Praveen Ranjan Srivastava, Automated generation of independent paths and
and state-based transformation also help to ensure the right code test suite optimization using artificial bee colony, Procedia Engineering 30
coverage for testing. The simulation results suggest that our (2012) 191–200.
firefly algorithm based approach has produced the optimal paths [18] Andreas Windisch, Stefan Wappler, Joachim Wegener, Applying particle
swarm optimization to software testing, in: Proceedings of the 9th Annual
below a given number of independent paths. Subsequently, it can Conference on Genetic and Evolutionary Computation, GECCO, ACM New
minimize the test efforts and provides the best critical test paths. York, NY, USA, pp. 1121–1128, ISBN: 978-1-59593-697-4,.
It can be expected that this method can also be applied for [19] X.S. Yang, Firefly algorithms for multimodal optimization, in: Stochastic
Algorithms: Foundations and Applications, SAGA, Lecture Notes in Computer
other expensive testing procedure by choosing the best possible
Sciences 5792 (2009), 169–178.
test paths for other applications. This can form a topic for further [20] R. Leidenfrost, W. Elmenreich: Establishing wireless time-triggered commu-
research. In addition, extensive parametric studies on the algo- nication using a firefly clock synchronization approach, in: Proceedings of the
rithm dependent parameters many provide further insight for 2008 International Workshop on Intelligent Solutions in Embedded Systems,
2008.
new ways to fine-tune the algorithm so as to suit a wider range of [21] J. Jumadinova, P. Dasgupta, Firefly-inspired synchronization for improved
applications. dynamic pricing in online markets, in: Proceedings of the 2008 IEEE
International Conference on Self-Adaptive and Self-Organizing Systems,
2008, pp. 403–412.
References
[22] K. Krishnanand, D. Ghose, Glowworm swarm optimization for simultaneous
capture of multiple local optima of multimodal functions, Swarm Intelligence
[1] Ian Sommerville, Software Engineering, eighth edition, Pearson Edition, Boston, 3 (2) (2009) 87–124.
2009. [23] Jeya Mala, V. Mohan, ABC tester—artificial bee colony based software test
[2] Aditya P. Mathur, Foundation of Software Testing, Pearson Education, India, suite optimization approach, International Journal of Software Engineering,
2007. IJSE 2 (2) (2009).
[3] J. Jenny Li, Prioritize code for testing to improve code coverage of complex [24] Huaizhong Li, C. Peng Lam, Software test data generation using ant colony
software, in: Proceedings of the 16th IEEE International Symposium on optimization, in: Proceedings of the World Academy of Science, Engineering
Software Reliability Engineering, ISSRE, Chicago, IL, 2005, pp. 84–93. and Technology, January 2005, vol.1 (2007), pp. 563–566.
[4] Y.K. Malaiya, M.N. Li, J.M. Bieman, R. Karcich, Software reliability growth with [25] P.R., SrivastavaBaby, Automatic test sequence generation for state transition
test coverage, IEEE Transactions on Reliability 51 (4) (2002) 420–427. testing via ant colony optimization, in: M. Chis, (Ed.), Evolutionary Computa-
[5] Robert Sedgewick, Algorithms in Java, Part 5: Graph Algorithms, third edition, tion and Optimization Algorithms in Software Engineering: Applications and
Addison Wesley, Boston, 2003. Techniques, 2010, pp. 161–183.
[6] V. Bhattacherjee, D. Suri, P. Mahanti, Application of regular matrix theory to [26] Robert Bradley; Anthony BrabazonMichael O’Neill, Objective function design
software testing, European Journal of Scientific Research 12 (1) (2005) 60–70. in a grammatical evolutionary trading system, in: Procedings of the IEEE
[7] W.E. Howden, Functional Program Testing and Analysis, McGraw-Hill, New Congress on Evolutionary Computation, IGI Global, Hershey, PA. CEC, pp. 1–8.
York, 1987. [27] Zhang Zhonglin, Mei,Lingxia, An improved method of acquiring basis path for
[8] Thomas Stutzle Marco Dorigo, The ant colony optimization metaheuristic:
software testing, in: Proceedings of the 5th International Conference on
algorithms, applications, and advances, International Series in Operations
Computer Science and Education, ICCSE, 2010, pp. 1891–1894.
Research and Management Science, vol. 57, Springer, New York, 2003
[28] Praveen Ranjan Srivastava, Optimal software release using time and cost
pp. 250–285.
benefits via fuzzy multi-criteria and fault tolerance, Journal of Information
[9] Li Huaizhong C. Peng Lam, An ant colony optimization approach to test
Processing System 8 (1) (2012) 21–24.
sequence generation for state based software testing, in: Proceedings of
[29] Xin-She Yang, Firefly algorithm, Lévy flights and global optimization, in:
the Fifth International Conference (IEEE) on Quality Software, QSIC, 2005,
pp. 255–264. M. Bramer, R Ellis, M. Petridis (Eds.), Research and Development in Intelligent
[10] P.R. Srivastava; K. Baby, G. Raghurama, An approach of optimal path Systems XXVI, Springer, London, 2010, pp. 209–218.
generation using ant colony optimization, in: Proceedings of the TENCON [30] Oliver Niggemann, Benno stein, A meta heuristic for graph drawing: learning
2009 - 2009 IEEE Region 10 Conference, Singapore, 2009, pp. 1–6. the optimal graph-drawing method for clustered graphs, in: Proceedings of
[11] Praveen Ranjan Srivastava, Km Baby, Automated software testing using the Working Conference on Advanced Visual Interfaces ACM, AVI, 2000.
metahurestic technique based on an ant colony optimization, in: Proceedings [31] P. Samuel, R. Mall, A.K. Bothra, Automatic test case generation using unified
of the International Symposium on Electronic System Design, ISED, Bhuba- modeling language (UML) state diagrams, IET Software 2 (2) (2008) 79–93.
neswar, December 2010, pp. 235–240. [32] Xin-She Yang, Seyyed Soheil Sadat Hosseini, Amir Hossein Gandomi, Firefly
[12] Doungsa-ard, K. Dahal, A. Hossain, T. Suwannasart, GA-based automatic test algorithm for solving non-convex economic dispatch problems with valve
data generation for UML state diagrams with parallel paths, Advanced Design loading effect, Applied Soft Computing 12 (3) (2012) 1180–1186.
and Manufacture to Gain a Competitive Edge, Springer, Berlin, 2008. [33] Amir Hossein Gandomi, Xin She Yang, Amir Hossein Alavi, Mixed variable
[13] Yong Chen, YongZhong, Automatic path-oriented test data generation structural optimization using Firefly algorithm, Computers and Structures 89
using a multi-population genetic algorithm, in: Proceedings of the Fourth (23–24) (2011) 2325–2336.