3
A Novelty Search-based Test Data Generator for Object-oriented Programs Mohamed Boussaa, Olivier Barais, Gerson Suny´ e, Benoit Baudry To cite this version: Mohamed Boussaa, Olivier Barais, Gerson Suny´ e, Benoit Baudry. A Novelty Search-based Test Data Generator for Object-oriented Programs. GECCO 2015, Jul 2015, Madrid, Spain. ACM, Proceedings of the Companion Publication of the 2015 Annual Conference on Ge- netic and Evolutionary Computation, pp.1359–1360, 2015, Proceedings of the Compan- ion Publication of the 2015 Annual Conference on Genetic and Evolutionary Computation. <http://www.sigevo.org/gecco-2015/>. <10.1145/2739482.2764716>. <hal-01248177> HAL Id: hal-01248177 https://hal.archives-ouvertes.fr/hal-01248177 Submitted on 24 Dec 2015 HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers. L’archive ouverte pluridisciplinaire HAL, est destin´ ee au d´ epˆ ot et ` a la diffusion de documents scientifiques de niveau recherche, publi´ es ou non, ´ emanant des ´ etablissements d’enseignement et de recherche fran¸cais ou ´ etrangers, des laboratoires publics ou priv´ es.

A Novelty Search-based Test Data Generator for Object ... · A Novelty Search-based Test Data Generator for Object-oriented Programs ... Gerson Sunye and Benoit Baudry ... spired

Embed Size (px)

Citation preview

A Novelty Search-based Test Data Generator for

Object-oriented Programs

Mohamed Boussaa, Olivier Barais, Gerson Sunye, Benoit Baudry

To cite this version:

Mohamed Boussaa, Olivier Barais, Gerson Sunye, Benoit Baudry. A Novelty Search-basedTest Data Generator for Object-oriented Programs. GECCO 2015, Jul 2015, Madrid, Spain.ACM, Proceedings of the Companion Publication of the 2015 Annual Conference on Ge-netic and Evolutionary Computation, pp.1359–1360, 2015, Proceedings of the Compan-ion Publication of the 2015 Annual Conference on Genetic and Evolutionary Computation.<http://www.sigevo.org/gecco-2015/>. <10.1145/2739482.2764716>. <hal-01248177>

HAL Id: hal-01248177

https://hal.archives-ouvertes.fr/hal-01248177

Submitted on 24 Dec 2015

HAL is a multi-disciplinary open accessarchive for the deposit and dissemination of sci-entific research documents, whether they are pub-lished or not. The documents may come fromteaching and research institutions in France orabroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, estdestinee au depot et a la diffusion de documentsscientifiques de niveau recherche, publies ou non,emanant des etablissements d’enseignement et derecherche francais ou etrangers, des laboratoirespublics ou prives.

A Novelty Search-based Test Data Generator forObject-oriented Programs

Mohamed Boussaa, Olivier Barais, Gerson Sunye and Benoit BaudryINRIA Rennes, France

{mohamed.boussaa, olivier.barais, gerson.sunye, benoit.baudry}@inria.fr

ABSTRACTIn search-based structural testing, meta-heuristic search tech-niques have been frequently used to automate test datageneration. In this paper, we introduce the use of noveltysearch algorithm to the test data generation problem basedon statement-covered criterion. In this approach, we seekto explore the search space by considering diversity as theunique objective function to be optimized. In fact, insteadof having a fitness-based selection, we select test cases basedon a novelty score showing how different they are comparedto all other solutions evaluated so far.

KeywordsSearch-based Software Testing, Structural Coverage, Auto-mated Test Data Generation, Novelty Search, Genetic Al-gorithm

1. INTRODUCTIONIn general, manually creating test cases for testing soft-

ware systems is time consuming and error-prone. Thus,the automation of this process becomes necessary. In fact,meta-heuristic search techniques such as Genetic Algorithms(GAs) are frequently used to automate the test data genera-tion process and gather relevant test cases through the widesearch space [3, 1]. These techniques are especially appliedfor structural white-box testing. For coverage-oriented ap-proaches, applying Evolutionary Algorithms (EAs) to testdata generation [4] has been focused on finding input datafor a specific path of the program in accordance with a cov-erage criterion (e.g., longest path executed). The problemwith coverage-oriented approaches is that search-based tech-niques cannot exploit the huge space of possible test data.In fact, some structures of the system may not be reachedsince they are executed only by a small portion of the inputdomain. The use of a fitness function as a coverage criterionto guide the search to detect relevant test data usually createone or more local optima to which the search may converge.

Permission to make digital or hard copies of part or all of this work for personal orclassroom use is granted without fee provided that copies are not made or distributedfor profit or commercial advantage and that copies bear this notice and the full citationon the first page. Copyrights for third-party components of this work must be honored.For all other uses, contact the owner/author(s).

GECCO ’15 July 11-15, 2015, Madrid, Spainc© 2015 Copyright held by the owner/author(s).

ACM ISBN 978-1-4503-3488-4/15/07.

DOI: http://dx.doi.org/10.1145/2739482.2764716

This process is known as diversity loss. Therefore, diver-sity maintenance in the population level is key for avoidingpremature convergence. This issue is a common problem inGAs and many techniques are proposed to escape from lo-cal optima in multi-modal search space [2, 6]. However, allthese alternatives use a fitness-based selection to guide thesearch.

In this paper, we propose the use of Novelty Search (NS)algorithm [5] to the test data generation problem. In thisapproach, we seek to explore the search space of possible testinput values by considering diversity as the unique objectivefunction to be optimized. In fact, instead of having a fitness-based selection, we rather select test cases based on a noveltyscore showing how different they are compared to all othertest data evaluated so far.

The paper is organized as follows: section 2 describes theapproach overview and our novelty search adaptation. Con-cluding remarks and future work are provided in section 3.

2. NOVELTY SEARCH FOR TEST DATAGENERATION

2.1 Approach OverviewOur test data generation framework aims to fully auto-

mate the test data generation process without requiring userintervention. In fact, we have considered our System UnderTest (SUT) as a gray or semi transparent box in where theinternal structure is partially known. Thus, we can designtest cases through the exposed interfaces and conduct a codecoverage analysis from the general structure of our targetSUT. For example, within apache.commons.math library,Methods Under Test (MUTs) are accessed through somespecific Java interfaces. Each interface belongs to a sub-package of the whole library and exhibits a set of methods.Our test data generation framework will rely on this con-cept to generate automatically test cases. In fact, as shownin Figure 1, starting from an input interface and a codesource package, the testing framework is able to: (1) gener-ate automatically sequences of method invocation throughthe input interface, (2) generate relative test data using NS,(3) execute test cases on target Classes Under Test (CUTs)and then (4) analyze code coverage within the source pack-age. The process is iterated until a termination criterion ismet (e.g., number of iterations)

In our proposal, we use the same logic as GAs to imple-ment the NS algorithm. However, we make some changesand we add new settings to optimize the test data genera-tion. In fact, instead of using a fitness function to evaluate

1359

Figure 1: Approach overview

generated test cases, we define a new measure of novelty tomaximize. We replace, as well, the fitness-based selection(for fittest test cases) with a novelty-based one. This mayfavor the diversity of generated test data. Finally, we add anarchive that acts as a memory of previously generated testcases. This archive is used to calculate the novelty metric.Otherwise, we keep the same settings as GAs, namely thecrossover and mutation operators.

For our NS adaptation, we have to define the number ofiterations N, the population size and the minimum coveragevalue. This latter defines the threshold of covered state-ments that should be reached. Test cases that exceed thisthreshold are automatically added to the set of relevant testcases. As well, we have to define a novelty threshold T thatdefines the threshold for how novel a test suite has to bebefore it is added to the archive. In addition, we define amaximum size limit for the archive L and a k number thatwill be used in calculating the novelty metric.

2.2 Novelty MetricThe Novelty metric expresses the sparseness of a test suite.

It measures its distance to all other test cases in the currentpopulation and to all test cases that were discovered in thepast (i.e., test cases in the archive). This measure expresseshow unique the test suite is. We can quantify the sparse-ness of a set of test cases as the average distance to thek-nearest neighbors. The distance between two test suitesis computed as a Manhattan distance between the input pa-rameter values of all methods tested in the test suite. Acandidate solution represents the set of methods signaturesdeclared in the interface. Thereby, we represent this solutionas a vector where each dimension has a method name, a listof parameters types and a list of test data (the genotype)Formally, we define this distance between two solutions asfollows :

distance(t1, t2) =

m∑i=1

p∑j=1

|t1(Mi, Pj)− t2(Mi, Pj)| (1)

where t1 et t2 are two selected test suites (solutions), m isthe number of methods composing the test suite, p is thenumber of parameters composing a method. The couple(Mi, Pj) returns the jth parameter value of the ith methodM relative to a test suite (t1 or t2). Since we are using

Java primitive types for test data such as floats, integers,doubles, etc, it is easy to calculate this distance for numericalparameters values. However, for string data types we use theLevenshtein Algorithm1 to measure the strings distance.

To measure the sparseness of a test suite, we will use thepreviously defined distance to compute the average distanceof a test suite to its k-nearest neighbors. In this context, wedefine the novelty metric of a particular solution as follows:

NM(S) =1

k

k∑i=1

distance(S, µi) (2)

where µi is the ith nearest neighbor of the solution S withinthe population and the archive of novel individuals. Fi-nally, we have normalized the resulted novelty distance inthe range [0-100].

3. CONCLUSION AND FUTURE WORKIn this paper, we proposed a new adaptation of the NS

algorithm to test data generation problem. Using the NSapproach is clearly a divergent evolutionary technique, in-spired by natural evolution’s drive to novelty that directlyrewards novel behaviors instead of progress towards a fixedobjective.

As a future work, we aim to conduct an empirical evalu-ation of our NS approach by comparing it to fitness-basedand random approaches. In addition, we can optimize ourapproach by adding diversity as an addition goal to a tra-ditional objective driven approach to form a multi-objectiveoptimization problem. Finally, since we are testing gray-box systems, we can apply this approach, as well, for black-box testing. In this case, we will be able to measure somenon-functional properties such as memory usage and CPUconsumption.

4. REFERENCES[1] S. Ali, L. C. Briand, H. Hemmati, and R. K.

Panesar-Walawege. A systematic review of theapplication and empirical investigation of search-basedtest case generation. Software Engineering, IEEETransactions on, 36(6):742–762, 2010.

[2] S. Das, S. Maity, B.-Y. Qu, and P. N. Suganthan.Real-parameter evolutionary multimodaloptimizationaATa survey of the state-of-the-art. Swarmand Evolutionary Computation, 1(2):71–88, 2011.

[3] M. Harman and P. McMinn. A theoretical andempirical study of search-based testing: Local, global,and hybrid search. Software Engineering, IEEETransactions on, 36(2):226–247, 2010.

[4] K. Lakhotia, P. McMinn, and M. Harman. Automatedtest data generation for coverage: Haven’t we solvedthis problem yet? In Testing: Academic and IndustrialConference-Practice and Research Techniques, 2009.TAIC PART’09., pages 95–104. IEEE, 2009.

[5] J. Lehman and K. O. Stanley. Exploitingopen-endedness to solve problems through the searchfor novelty. In ALIFE, pages 329–336, 2008.

[6] H. M. Pandey, A. Chaudhary, and D. Mehrotra. Acomparative review of approaches to prevent prematureconvergence in ga. Applied Soft Computing,24:1047–1077, 2014.

1http://www.levenshtein.net/

1360