its normal behaviour or exhibit different activity in contrast to its specification. Software testing has a major role in software development lifecycle (SDLC) [2] to.
Test Case Optimization Using Artificial Bee Colony Algorithm AdiSrikanth, Nandakishore J. Kulkarni, K. Venkat Naveen, PuneetSingh, and PraveenRanjanSrivastava Computer Science & Information System Department, Bits Pilani – 333031 (India) {adisriikanth,kvenkatnaveen,nandkishorejk, puneet.mir,praveenrsrivastava}@gmail.com
Abstract. Software Testing is one of the integral parts of software development lifecycle. Exhaustive testing on software is impossible to achieve as the testing is a continuous process. Using this as a constraint, software testing is performed in a way that requires reducing the testing effort but should provide high quality software that can yield comparable results. To accomplish this optimized testing, a software test case optimization technique based on artificial bee colony algorithm is proposed here. Based on intelligent behavior of honey bee, this method generates optimal number of test cases to be executed on software under test (SUT). This approach is qualified by self-organization, robustness and focuses on generation of paths derived from cyclomatic complexity. The resulting solution guarantees full path coverage. Keywords: Software Testing, ABC (Artificial Bee Colony Optimization), TestCase, Agents, Path-Coverage, optimal path, cyclomatic complexity, CFG (Control Flow Graph), test data.
1 Introduction Software Testing [1] involves identifying the conditions where software deviates from its normal behaviour or exhibit different activity in contrast to its specification. Software testing has a major role in software development lifecycle (SDLC) [2] to develop the high quality software product [1]. At least, software testing consumes 50% of the development cost. Software testing [1] in the context of this paper is focused around path testing, a form of functional testing which concerns about path coverage [2] that is finding all possible execution sequence within code. Software testing [1] is an optimization [2] process where multiple variables are taken into account to generate the efficient number of test cases and to provide the optimal path. Infinite number of test cases will be generated by use of exhaustive testing [1] [2]. However, only a part of them will be more effective if implemented in testing the software. This approach leads the tester to obtain the comparable results using reduced and optimal set of test cases. Independent paths are useful in testing the path coverage and code coverage. Independent paths of SUT are identified using the CFG (control flow graph) [1]. CFG is a representation of different paths using the graphical notation. Paths generated by A. Abraham et al. (Eds.): ACC 2011, Part III, CCIS 192, pp. 570–579, 2011. © Springer-Verlag Berlin Heidelberg 2011
Test Case Optimization Using Artificial Bee Colony Algorithm
571
CFG are traversed by the test cases [1] to be prioritized based on some test adequacy criteria or fitness value [3]. This perception drove the tester to develop an alternative approach based on search based intelligent selection and prioritization of test case. The meta-heuristic methods[5][7][9][10]tried in past to solve this problem yielded success, but with serious drawbacks such as operating on dynamic data sets may be difficult and can also converge early towards the solution which may not be useful later in further testing process. Using polynomial bounded computation many of the complex multivariable optimization problems [4] cannot be solved accurately. The optimal number of test-cases in covering the SUT provides better performance than other meta-heuristic approaches. The ABC algorithm [3][11][12], a meta-heuristic approach [10]is used to generate the optimal number of test-cases which are sufficient to cover the paths generated by using the CFG (control flow graph)[1].The independent paths are considered to be an important criterion to generate the effective test cases for path coverage [1][2]. The effective test-cases are those which cover all the nodes of the path in less time. The proposed tool focuses more on the independent paths generated by using CFG to find optimal path[3][11], the paths are traversed using the test data providing path coverage and these test data sets are optimized using ABC[3][11]. Finally the paper compares ABC with GA (genetic algorithm) [5][7][8] and ACO (ant colony optimization) [9][10][13] to differentiate the performance and efficiency issues.
2 Background Work There are several research approaches that have been proposed which attempted to reduce the number of test-cases [2] using ACO (ant colony optimization) [9] [13] and GA (genetic algorithms) [5] [6] [7]. GA (genetic algorithms) [5][6] is a population based approach uses the genetic operators to derive the fitness function and calibrate the efficient test-cases. But, there are some demerits like the external optimization in the GA that provides a single solution where the local optimum can be modified for the worst cases rather than the global optimum, which makes result less stable. And GA not quite effectively solves the problems involving only one measure for judging purpose, as it is not sufficient to converge to a solution. ACO [9] [13] shows the behaviour of the ants which is based on the randomization of the ant behaviour. The time to process and generate the effective number of testcases wastes large amount of computing resources. It also produces inefficient higher length test sequences and repetition of nodes in same sequence and eliminates the use of fitness value. The proposed approach is aimed to generate the optimal number of test cases and to achieve greater path coverage. To solve this problem ABC[3][11] approach is used where the bee agents [3] gather the food sources (test cases) and then calibrate the fitness function[11]which is in-turn used to identify the optimal test cases with highest path-coverage[2] using less amount of resources.
572
ASrikanth et al.
3 Artificial Bee Colony (ABC) Algorithm The Artificial Bee Colony (ABC) [3] [11] algorithm is a population-based evolutionary, stochastic method that can be implemented on a wide range of problems, including global optimization. It’s also a type of swarm intelligence algorithm for the same. ABC algorithm is derived and motivated by the behaviour of Bees [12]. Bees follow a certain protocol based searching and extracting honey. The search behaviour and its intelligence propelled to use ABC in rendering optimised Test Suite. The optimised Test suite will not only cover all the code, it also can be used for path testing. The ABC algorithm is biologically enlivened technique of swarm intelligence for searching [12]. It’s about honey bees’ collective foraging and work distribution skill to amass surplus nectar for their survival [3]. In ABC, the colony of the artificial bees comprises three groups of bees: employed bees, onlookers and scouts. Food Positions are altered by Artificial Bees with time. Bees aim is to find out the places of food sources with high nectar amount. Employed and Onlookers bees select food sources depending on the experiences of themselves and their nest mates.
4 Proposed Strategy The proposed approach attempts to solve the problem of Test Case Optimization by applying ABC algorithm. In the proposed approach each test case would represent a food source and the goal of the approach would be to find best food sources i.e. test cases with maximum coverage. The food source position represents to a possible solution of the optimization problem and the nectar amount corresponds to the quality (fitness) of the associated solution. The basic steps of ABC algorithm [3] [11] [12] are: Station the Search bees onto the food sources and ascertain their nectar amount. • • • •
Compute the probability value of the sources with which they are opted by the Selector bee. The process of the traversing of the food sources by desolated bees is halted. The scouts are sent into the search area for exploring new food sources randomly. The best food source found so far is retained in the memory
As explained earlier the entire functionality is divided as the functions of three kinds of bees. The three kinds of bees act as [12]: • • •
Search bee which act as Search agent Selector bee which acts as Selector agent Scout bee which acts as Replace agent
The principle and working of the proposed approach: The approach is a population based approach [9]. Here each test case comprises the possible solution in the optimization problem. The fitness value of each test case equates to the quality or the fitness of the colligated solution. An outline of the solution is presented the figure 1. The work proposes that the Optimised test suite generated by using the algorithm will contain all possible independent paths along with its test data.
Test Case Optimization Using Artificial Bee Colony Algorithm
573
Fig. 1. Architecture/High level flow of the algorithm
The test data will be the required input to be given to the SUT, for travelling along the path and vice versa. Initially the program is fed to the Test Case optimization tool, which converts the program into a corresponding Control Flow Graph (CFG). Now from control flow graph, the independent paths from the start node to the end node are generated. Each independent path would comprise number of normal nodes and predicate nodes. Every independent path would represent a Test Case [1].Now the ABC algorithm is applied to generate an Optimal Test suite by generating optimal test data which would traverse through the independent paths and hence into to the test cases. Consider the figure 1. Here the search bee acts as search agent which searches for the execution state of the SUT and also initialises the test cases with the initial test data with the help of equivalence partitioning and boundary value analysis [19]. Then the search agent calculates the fitness value of each test node by computing the coverage of each node. This process is repeated until an executable state of SUT is found. Then the search bee passes the fitness value of the traversed nodes/neighbouring nodes to the selector agent. The selector bee compares the fitness value of nodes with the fitness value of the neighbouring nodes. If the node’s fitness value is found greater than the neighbouring node’s fitness value, the node’s information is stored in the optimal test case repository. The node whose fitness value is found less is pushed to the abandoned repository. The scout bee generates the new set of test data from the abandoned repository and again the same procedure of search bee is repeated. The algorithm for test case optimization using Artificial Bee Colony optimization approach is presented in the next section.
5 ABC Optimization Algorithm Initialize the Test Cases by initial test data generated by the tool. Initial test data is generated by the equivalence partitioning and boundary value analysis methods.
574
ASrikanth et al.
Step 1: The search bee employ test cases to the first executable node of the program. The fitness value of the test cases and the node information is returned to the employed bees. Step 2: The Selector Bee takes the node information and fitness value of the test cases as the input and evaluates the fitness of each test case taken from the employed bees. Then the test case with the highest fitness value is stored in the memory or repository. Step 3: Then the neighbouring nodes of the covered nodes are searched by the employed bees and the fitness value of the current test case is explored against the neighbouring nodes by the onlooker bee. Step 4: The node with the highest fitness value is picked out and tagged with the current node which forms the test path. This information of the test path is stored in the Optimal Test repository. Step 5: Rest of the nodes other than the covered node and the test cases other than the selected test case are abandoned and they are stored in a temporary abandoned repository. Step 6: Repeat the steps 3 to 6 till the test path is not complete Else the nodes and the test cases from the abandoned repository are selected for the next test path generation by the employed bees Step 7: The scout bee bring forth a new population of test cases and replaces the test cases of the abandoned repository with the new test cases if the onlooker bee finds the selected test cases are not efficient. Until the user defined termination criterion is met. In order to implement any algorithm, the algorithm must be converted into the pseudo code before programmatically developing an application. The detailed pseudo code of the Test Case Optimization algorithm using ABC approach is presented in the following section. The following is the detailed algorithm 1. 2. 3. 4. 5.
Initialise the test cases which is performed by the search bee(see figure 1) Search for an executable state and evaluate the test nodes Initialise the current traversal path as cycle=1 Repeat Produce new test cases vij in the neighbourhood of xij for the the search agent using the formula Xij=minj+rand (0, 1)*(maxj-minj) [15] • Xij is the initial test case • minj is the minimum no. of test cases • maxj is the maximum no. of test cases • rand () is a random number generation function which selects either 1 or 0 randomly. 6. Generate the test data using equivalence partitioning and boundary value analysis [19]. 7. Apply greedy selection process [18] for the generated test data. 8. Traverse the SUT with the generated Test Data and calculate the fitness value.
Test Case Optimization Using Artificial Bee Colony Algorithm
575
9.
The onlooker selects the test cases with the highest fitness value and abandons the rest 10. The traversal process is carried out till a particular test data with 100% fitness value and 0% fitness value is produced Pi=(fiti)/∑(fiti) [16] Where Pi isthe probability function which signifies the probability with which the ithtest data traversers a independent test path successfully. 11. Add the test case to the optimal repository 12. In the next iteration scouts generate the new test data and go to step 5 To implement the above algorithm, our approach uses the ABC Test Suite Optimization tool to optimize the Test Cases by employing the ABC algorithm. The tool considers a program as an input to generate independent paths. Using the generated independent paths Test Cases are traversed along the paths with the help of ABC algorithm. By doing so the test cases with maximum coverage (High fitness Value) are recognized. Finally the optimal Test Suite is generated.
6 Case Study The proposed algorithm is applied and tested for various real time applications, for illustration purpose this paper is used Quadratic Equation solving program Two case studies are discussed in the paper. Case Study This Case Study’s SUT code is available in APPENDIX. The SUT uses 3 inputs of a quadratic equation and generates its roots. Nodes are represented in the code at APPENDIX. The Control Flow Graph (CFG) for the APPENDIX is given below.
Fig. 2. CFG of the Quadratic Equation Code
The program in the appendix will find out the root of the quadratic equation and specify whether they are real or imaginary.
576
ASrikanth et al.
Source Code of the program is provided as input to the tool. Links to the different nodes are provided as a text document which also acts as an input to the tool. The onlooker bee generates different paths of the SUT. For the above program of 6 nodes following are the generated independent paths. 1. 1-2-6 2. 1-3-5-6 3. 1-3-4-6 According to proposed algorithm following steps happen. 1. All the 3 independent paths are initialized as test cases by the search bee 2. Initialise the current traversal path as cycle=1 3. Repeat 4. Produce new test cases, xij for the search agent using the formula Xij=minj+rand (0, 1)*(maxj-minj) (1) Xij is the initial test case minj is 1 here (as minimum numbers of test cases are 1) maxj is 3 here (as maximum numbers of test cases are 1) Hence, Xij= 1 + 0 * 3-1 = 1 So, path number 1 i.e., 1-2-6 is selected by selector bee as it traverses the path 1-26 completely. 5. Generate the test data using equivalence partitioning and boundary value analysis [19] by analysing the code. 6. Traverse the SUT with the generated Test Data and calculate the fitness value. 7. The onlooker selects the test cases with the highest fitness value and abandons the rest For the path 1-2-6, the test data (1,4,3), (1,4,4), (2,3,4) and (2,3,1) are tested by traversing along the path 1-2-6 which are generated using equivalence partitioning and boundary value analysis. In test data (1, 4, 3) covered node 1, node 2 and node 6 completely. Hence the fitness value of (1, 4, 3) with respect to path 1-2-6 is 100%. Similarly the test data (1, 4, 4), (2, 3, 4) and (2, 3, 1) are traversed through the path 1-2-6. But they don’t cover the test nodes 1, 2 and 6 completely. Hence the fitness value for the data (1, 4, 4) ,(2, 3, 1),(2,3,4) are 0%. So test data for the case study will be 1, 4, 3 and 1, 4, 4(One of the test data which didn’t traversed the complete path 1-2-6). 8. In the next iteration scouts generate the new test data and go to step 5 of the above mentioned algorithm 9. Optimised test data is added to the repository 10. Go to Step 1 and continue the process for other test paths. S.No.
Test Sequence
Test Cases
Coverage or Fitness Value
1 1 2 2 3 3
1-2-6 1-2-6 1-3-5-6 1-3-5-6 1-3-4-6 1-3-4-6
1,4,3 1,4,4 2,3,4 2,3,1 2,4,2 2,4,3
100 0 100 0 100 0
Where fitness values is 100 for complete traversal and 0 for incomplete So, the optimal test suite is generated successfully for the above program.
Test Case Optimization Using Artificial Bee Colony Algorithm
577
7 Analysis and Comparison With Bee System, the probability of falling into a local optimum is low because of the combination of local and global search since the aim of the algorithm is to improve the local search ability of genetic algorithm without degrading the global search ability. From Figure 3, observe that, as the number of cycle’s increases, percentage of paths covered increases and after a particular threshold, it achieves complete coverage and maintains consistency. Path Coverage for the ABC testing based on cycles.
Fig. 3. Number of Cycles vs. Percentage Covered
Fig. 4. Number of Paths vs. Runs
Fig. 5. Number of nonfeasible paths vs. KLOC
The graph from Figure 4 plots the number of paths and runs taken to achieve the number of paths which increased incrementally. The line of graph is having lesser slope. The Figure 5, graph plots comparison between ABC, ACO [9] [13], and GA [5] [6] for number of non-feasible paths against the LOC. This graph testifies that the ABC distinguishes and accounts less number of non-feasible paths. Thus more number of feasible paths with test data is covered. But GA doesn’t find any non-feasible paths. Non-feasible paths are the paths which cannot be traversed using any generated test data. Hence, the non-feasible path is technically accessible but logically cannot be traversed. The previous approach[15] of ABC didn’t mention anything about feasible paths but the proposed approach in this paper will return non feasible paths if any path generated using ABC is not reachable using any test data.
8 Conclusions and Future Work In this paper, test case optimisation is done using ABC. The proposed algorithm uses ABC approach to work with faster and efficient ways for generating optimised test suite. Also the algorithm is compared to previous algorithms and older ABC approaches, and the results confirm that the proposed algorithm is beating other algorithms and approaches. In the proposed ABC approach, optimised test suite is generated for each independent path of the program where each path will have two types of data. One is the test data which traverses the path with 100% coverage and the other which traverses the path with 0% coverage. The bee searches a path until we find the 100% fitness valued (coverage) test data. The bee searches a path until we find the 100 fitness valued test data. Prioritization in ABC is presently done using factors like code complexity, application feasibility and implementation complexity.
578
ASrikanth et al.
In future, more factors can be added to increase the efficiency of the ABC approach and give more prioritised and optimised test suite.
References 1. Pressman, R.S.: Software Engineering: A practitioners Approach, 6th edn., ch.1 (3347),13(387-406),14(420-444). McGraw-Hill, New York (2007) 2. Sommerville: Software Engineering, 8th edn., ch.1 (27-42), 11(265-288), 23(561-589). Pearson, London (2007) 3. Basturk, B., Karaboga, D.: A powerful and efficient algorithm for numerical function optimization: artificial bee colony(ABC) algorithm. In: Proceedings of the IEEE Swarm Intelligence Symposium, pp. 459–471. IEEE, Indianapolis (2006) 4. KDeb: Multi-Objective optimization using Evolutionary Algorithms, 1st edn., ch.4 (140). John Wiley & Sons, UK (2001) 5. Christoph, C., Michael Gary, E., Michael, M., Schatz Curtis, A., Walton, C., et al.: Genetic Algorithms for Dynamic Test Data Generation. In: Proceedings of the 12th International Conference on Automated Software Engineering (ASE), pp. 307–308. IEEE, Washington, DC, USA (1997) 6. Johnson, D.L., Pinglikar, J., Watkins, A., et al.: Breeding Software Test Cases withGenetic Algorithms. In: Proceedings of the 36th Annual Hawaii International Conference on System Sciences, p. 10. IEEE, Hawaii (2003) 7. Michael, C.C., McGraw, G., Schatz, M.A.: Generating Software Test Data by Evolution. IEEE Transactions on Software Engineering, 1085–1110 (2001) 8. Lin, J.C., Yeh, P.L.: Using Genetic Algorithms for Test Case Generation in Path Testing. In: Proceedings of the 9th Asian Test Symposium (ATS), pp. 241–246. IEEE, Taiwan (2000) 9. Wagner, I.A., Lindenbaum, M., Bruckstein, A.M.: ANTS: Agents, Networks, Trees, and Subgraphs. In: Dorigo, M., Di Caro, G., Stützle, T. (eds.) Special Issue on Ant Colony Optimization, Future Generation Computer Systems, pp. 915–926. ACM, North Holland (2000) 10. Lawrence, S.: Resource constrained project scheduling: an experimental investigation of heuristic scheduling techniques (Supplement). PhD thesis, Graduate School of Industrial Administration, Carnegie-Mellon University, pp. 1–15. ACM, Pittsburgh(1984) 11. Dahiya, S., Chhabra, J., Kumar, S.: Application of Artificial Bee Colony Algorithm to Software Testing. In: Software Engineering Conference (ASWEC), pp. 149–154. IEEE, Auckland (2010) 12. Karaboga, D., Bahriye, A.: A survey: algorithms simulating bee swarm intelligence. Artificial Intelligence Review, 61–85 (2009) 13. Alaya, I., Solnon, C., Ghedira, K.: Ant Colony Optimization for Multi-Objective Optimization Problems. In: Proceedings of the 19th IEEE International Conference on Tools with Artificial Intelligence, pp. 450–457. IEEE, Washington, DC, USA (2007) 14. Karaboga, D., Basturk, B.: On The PerformanceOf Artificial Bee Colony (ABC) Algorithm. In: Applied Soft Computing, pp. 687–697. Elsevier Science Publishers B. V., Amsterdam, ACM, Netherlands (2008) 15. Jeya Mala, D., Mohan, V.: ABC Tester - Artificial Bee Colony Based Software Test Suite Optimization Approach. International Journal of Software Engineering, IJSE, 1–33 (2009) 16. JeyaMala, D., Kamalapriya, M., Shobana, R., Mohan, V.: A Non-Pheromone based Intelligent Swarm Optimization Technique in Software Test Suite Optimization. In: Intelligent Agent & Multi-Agent Systems (IAMA), pp. 1–5. IEEE, Chennai (2009)
Test Case Optimization Using Artificial Bee Colony Algorithm
579
17. Liu, Z., Gu, N., Yang, G.: An automate test case generation approach: using match technique. In: The Fifth International Conference on Computer and Information Technology (CIT), pp. 922–926. IEEE, Shanghai (2005) 18. Kodaganallur, V., Sen, A.K.: Greedy by Chance - Stochastic Greedy Algorithms. In: Sixth International Conference on Autonomic and Autonomous Systems, pp. 182–187. IEEE, Washington, DC, USA (2010) 19. Reid, S.C.: An empirical analysis of equivalence partitioning, boundary value analysis and random testing. In: Software Metrics Symposium, Proceedings, Fourth International, Albuquerque, NM, USA, pp. 64–73 (1997) 20. Korman, T.H.: Introduction to Algorithms, 2nd edn., ch.21. McGrawHill, New York (2001)
Appendix – 1 x2 1. int main() { int A,B,C; float disc,deno,x1,x2; printf("\n\n PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION "); printf("\n\n\t ENTER THE VALUES OF A,B,C..."); scanf("%d,%d,%d",&A,&B,&C) ; disc = (B*B)-(4*A*C); deno = 2*A; if(disc > 0) 2. { printf("\n\t THE ROOTS ARE REAL ROOTS"); x1 = (B/deno)+(sqrt(disc)/deno);
Screen Shots
=
(-B/deno)-
(sqrt(disc)/deno); printf("\n\n\t THE ROOTS ARE...: %f and %f\n",x1,x2); } 3. else if(disc == 0) 4. { printf("\n\t THE ROOTS ARE REPEATED ROOTS"); x1 = -B/deno; printf("\n\n\t THE ROOT IS...: %f\n",x1); } 5. else printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n"); printf("\n------------------------------------------------------"); getch(); 6.}