Generating Prioritized Test Sequences Using ... - Semantic Scholar

3 downloads 0 Views 309KB Size Report
tional to the square of the distance, say d, from the source. Thus, the intensity at. I (d) varies according to the inverse square law, i.e. I (d) = Is/d2 where Is is the.
Generating Prioritized Test Sequences Using Firefly Optimization Technique Vikas Panthi and D.P. Mohapatra

Abstract The aim of this study is to propose an algorithm for generating minimal test sequences by applying Firefly optimization technique. In this study, we use state machine diagram for the behavioral specification of software. This paper generates the important test sequences for composite states in the state machine diagram under consideration. The generated test sequences are then prioritized based on a software coverage criterion. The use of firefly technique results in efficient prioritization of the generated test sequences. Keywords Test sequence Composite model



Firefly optimization algorithm



State machine



1 Introduction Software testing is one of the most important parts of quality assurance in software development life cycle. Increase in complexity and size of software requires more manpower and time for testing the software systems. Manual testing is very much labor-intensive and error-prone. Therefore software testers need novel approaches, which are reliable and automatic for test case generation [2]. Test sequence generation contributes a large part to testing cost. It is generally agreed that manual testing is a construction and is a frequent cause of project delays, especially for large projects. Therefore, automatic test sequence generation has become important to ensure the quality of present day large software products and to contain the apace growing testing costs. As it is very difficult to generate test V. Panthi (&)  D.P. Mohapatra Department of Computer Science and Engineering, National Institute of Technology, Rourkela 769008, Odisha, India e-mail: [email protected] D.P. Mohapatra e-mail: [email protected] © Springer India 2015 L.C. Jain et al. (eds.), Computational Intelligence in Data Mining - Volume 2, Smart Innovation, Systems and Technologies 32, DOI 10.1007/978-81-322-2208-8_57

627

628

V. Panthi and D.P. Mohapatra

sequences from source codes, a substitute approach is to generate test sequences from UML models constructed during the design process. UML is a widely accepted modeling language for object-oriented systems. It has various diagrams for depicting the behavior of objects in a system. Test sequence generation from design models has several rewards. Model based test sequence generation technique can detect sealed categories of faults that are not easily detected by source code based testing. It also allows test cases to be available much earlier in the software development process, thereby making test planning more efficient, and reduces the rescue time and usage of resources [1, 4]. To generate optimal test sequences and to prioritize the test sequences is still a challenging task. So we use Firefly optimization algorithm for prioritization of test sequences. Firefly algorithm is becoming powerful in solving the modern numerical optimization problems, especially for the NP-hard problem (traveling salesman). So we can also apply this approach on CFG for test sequences generation which is also an optimization problem. As compared to Genetic Algorithm (GA) and Particle Swarm Optimization (PSO) techniques, Firefly Algorithm (FA) reduces the overall computational effort by 86 and 74 %, respectively [6]. We consider composite states in the state machine diagram to extract test sequences and to verify the behavior of state machines. This paper generates all possible valid test sequences for the software to be tested and employs FA to prioritize the generated test sequences. The rest of the paper is structured as follows: Sect. 2 provides an overview of the Firefly optimization algorithm and vector space basis. Section 3 presents the proposed approach for prioritizing the test sequences generated from the state machine model using FA. Section 4 describes the state machine model of a Bank ATM system taken as a case study. This section also discusses the experimental studies and presents the corresponding result analysis. Section 5 concludes the paper and provides some insight into our future work.

2 Preliminaries In this section we discuss some of the basic concepts required for understanding of our proposed approach. In Sect. 2.1, we discuss the basics of Firefly algorithm and Sect. 2.2 discusses the concept of Vector space basis.

2.1 Firefly Algorithm (FA) Firefly is a bio-inspired meta-heuristic algorithm introduced by Yang [5] and is used to solve optimization problems. According to Yang [5] there are three important assumptions in firefly algorithm [3, 5]:

Generating Prioritized Test Sequences …

629

1. All fireflies are unisex, which means any firefly can be attracted to any other brighter one. 2. Attractiveness is proportional to their brightness, thus for any two flashing fireflies, the less bright one will move towards the brighter one. The attractiveness is proportional to the brightness and they both decrease as their distance increases. 3. The firefly will move towards the brighter one, and if there is no brighter one, it will move randomly. Based on these three rules, the basic steps of a firefly algorithm (FA) can be summarized into two basic concepts: variation of light intensity and formulation of the attractiveness. For simplicity, this paper assumes that the attractiveness of a firefly is determined by its brightness. The intensity of light is inversely proportional to the square of the distance, say d, from the source. Thus, the intensity at I (d) varies according to the inverse square law, i.e. I (d) = Is/d2 where Is is the intensity at source point. In the simplest format, the brightness on intensity I of a firefly are at a particular location x can be chosen as I(x) ∝ f(x). When light passes through a medium with light absorption coefficient of λ, the light intensity I, varies with distance say d as given below [5]: I ðd Þ ¼ I0 ek d

2

ð1Þ

where I0 = Intensity at the origin point. The approximation of the Gaussian form in Eq. 1 obtained by using combined effect of inverse square law and absorption is given below: I ðd Þ ¼

I0 1 þ kd 2

ð2Þ

For a shorter distance Eqs. 1 and 2 are essentially the same. This is because the series expansions at d = 0 is given in Eq. 3. ekd  1  kd 2 þ 2

1 2 4 1 1 k d þ ;  1  kd 2 þ k2 d 4 þ    ; 2 1 þ kd 2 2

ð3Þ

Similarly, the attractiveness of a firefly can be defined as follows: Aðd Þ ¼

A0 1 þ kd 2

ð4Þ

where A0 is the attractiveness at d = 0, and A(d) is the attractiveness of the node at a distance d. The movement of a firefly i, that is attracted to another more attractive (brighter) firefly is determined by using Eq. 5 as follows:

630

V. Panthi and D.P. Mohapatra

 2  1 xi ¼ xi þ A0 ek dij xi  xj þ a ðrand þ Þ 2

ð5Þ

where   dij ¼ xi  xj  ¼

sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi n  X 2 xi;k  xj;k

ð6Þ

k¼1

Here, xi,k is the kth component of the spatial coordinate xi of the ith firefly. In 2D form, we have dij ¼

qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi  2  2ffi xi  xj þ y i  y j

ð7Þ

In Eq. 5 the second term corresponds to the attraction and the third term is for randomization with α being the randomization parameter and 0 ≤ α ≤ 1. rand is a random number generated between [0, 1].

2.2 Vector Space Basis Vector space is also called linear space. Let V be the set of n-dimensional vectors. If the set V is nonempty, and closed under finite vector addition and scalar multiplication, where the scalars are the members of a field F, we say V is a vector space over F. Furthermore, a vector space should satisfy some axioms. We shall not list all those assumptions. The details may be found in any linear algebra book. If a vector set {v1, v2, …, vk} in a vector space V is linear independent and this set spans V, we say that elements v1, v2, …, vk form a basis of V, which means that all vn in V can be expressed uniquely as a linear combination.

3 Proposed Algorithm In this section, we discuss our proposed approach for automatically generating and prioritization test sequences using FA. The schematic representation of our approach is given in Fig. 1. Our approach for generation and prioritization of the test sequences is explained below. Step 1: Construct the state machine diagram for the given project or the program. Step 2: Convert the State Machine Diagram (SMD) to CCFG (Composite Control Flow Graph). Step 3: Convert CCFG to Feasible Control Flow Graph (defined in Sect. 4).

Generating Prioritized Test Sequences …

631

Fig. 1 Schematic procedure of the proposed approach

Step 4: Analyze and collect all the possible Feasible Test sequences using Feasible Control Flow Graph. Step 5: Choose number of fireflies at each node. I0 Step 6: Generate the fireflies at each node by using IðdÞ ¼ 1þkd 2 where I0 = 10, λ = Cyclomatic complexity at node of graph, d = random distance for brightness. Step 7: Calculate mean of brightness at every path. Step 8: Calculate priority of the paths using the following formula. Highest priority ∝ Highest mean brightness Step 9: Exit.

4 Case Study We consider a Bank ATM system for our case study. We construct the state machine diagram for the Bank ATM system as shown in Fig. 2 using IBM Rational Software Architecture (RSA) tool. The initial state of the ATM is shown to be turned off. After the power is turned on, the ATM performs startup action and enters selfTest state. If the test fails, then the ATM goes into outofService state, otherwise, there is a triggerless transition to the Idle state. In this state, ATM waits for customer interaction. The ATM state changes from Idle to ServingCustomer state as soon as the customer inserts banking or credit card details through the ATM card reader. On entering the ServingCustomer state, the entry action readCard is

632

V. Panthi and D.P. Mohapatra

Fig. 2 State machine diagram of bank ATM system

performed. Note that the transition from ServingCustomer state back to the Idle state could be triggered by cancel event, as the customer can cancel the transaction at any time. The servingcustomer state is a composite state with the sequential substates such as CustomerAuthentication, SelectingTransaction and Transaction. CustomerAuthentication and Transaction are composite states by themselves, which are shown with hidden decomposition indicator icon. ServingCustomer state has a triggerless transition back to the Idle state after the transaction is finished. The state also has an exit action, ejectCard, which ejects the customer card on exiting the state, no matter what caused the transition outofService state. We generate a XML document from State Machine Diagram (SMD). Then, we parse the XML file and calculate the number of states, transitions and cyclomatic complexity for every node and construct the corresponding composite control flow graph (CCFG). The nodes of the CCFG correspond to the different states in SMD and the edges correspond to the transition events. The CCFG of the SMD in Fig. 2 is shown in Fig. 3a. After calculating all the required elements, we convert the CCFG into Feasible Control Flow Graph (FCFG) for generating the feasible test sequences of the state machine diagram. This conversion is carried out to remove the presence of loops and redundant states in CCFG due to the composite nature of the states (Table 1). In FCFG, every node is associated with number of fireflies present in the test sequences. Through these test sequences, fireflies can transmigrate to the next state of the state sequence according to the attraction of fireflies by brightness. After completing the process of attraction, fireflies are able to reach the end node. Table 2 shows the cyclomatic complexity computed for every node by using Eq. 7.

Generating Prioritized Test Sequences …

633

Fig. 3 Composite control flow graph (a) and feasible graph structure of composite control flow graph (b) of bank ATM system in Fig. 2

CC ¼ EN þ 2

ð7Þ

Here, CC = cyclomatic complexity of CCFG, E = No. of edges in CCFG and N = No. of nodes in graph. Test sequence prioritization includes scheduling of the test cases in sequential manner to improve the performance of the regression testing. In the proposed approach, hundred fireflies are at each node and they traverse each feasible test sequence by using the firefly optimization algorithm. The screenshot of the obtained prioritized test sequences is shown in Fig. 4. For all the test sequences, hundred fireflies are transmitted at every node as inputs in accordance to Eq. 4.

634

V. Panthi and D.P. Mohapatra

Table 1 Cyclomatic complexity list for every node (state) S. no

State

Cyclomatic complexity

1 2 3 4 5 6 7 8 9 10

S0 S1 S2 S3 S4 S5 S6 S61 S62 S63

8 8 7 5 4 3 3 3 3 10

Table 2 Generated feasible test sequences for FCFG shown in Fig. 3b Test Feasible test sequences Sequence ID

Brightness value

TS1

S0 → S1 → S2 → S3 → S1E

40.8087

TS2

S0 → S1 → S2 → S3 → S4E

55.5104

TS3

S0 → S1 → S2 → S3 → S6S → S61 → S6 → S63 → S6E

TS4

S0 → S1 → S2 → S3 → S6S → S61 → S6 → S63 → S6E → S5E 224.315

227.928

TS5

S0 → S1 → S2 → S5 → S1E

62.5211

TS6

S0 → S1 → S2 → S5 → S4 → S2E

77.3287

TS7

S0 → S1 → S2 → S5 → S4 → S5E

100.8452

Fig. 4 Prioritized test sequences for stat machine diagram of ATM system

Generating Prioritized Test Sequences …

635

We assume, A0 ¼ 10; d ¼ ½0:9; . . .; 1:0 to ½0; . . .; 0:1; λ = Cyclomatic complexity of the node under consideration. The prioritized optimal test sequences of state machine diagram for Bank ATM system is based on the brightness values. Prioritized test sequences:

TS3 ! TS4 ! TS7 ! TS6 ! TS5 ! TS2 ! TS1

5 Conclusion and Future Work This paper presented a Firefly optimization based approach for test sequence generation and prioritization using composite state in state machine diagram. Using the proposed algorithm, a group of fireflies can effectively explore the UML state machine diagram and automatically generate test sequences to achieve the test adequacy requirement. To our knowledge, there exists no such technique that generates test sequences by considering the composite states. In such a scenario, we believe that the generated test sequences are both optimal and minimal. Redundant exploration of the state diagrams and the iteration over the state loops are avoided by the construction of the Feasible Control Flow Graph. The use of Firefly Algorithm, resulted in efficient prioritization of the generated test sequences. In future, we focus to prioritize the test sequences by adopting some heuristic algorithms and compare their respective results.

References 1. Kalaji, R., Hierons, M., Swift, S.: A search-based approach for automatic test generation from extended finite state machine (EFSM). In Testing: Academic and Industrial Conference-Practice and Research Techniques (IEEE) (2009) pp. 131–132 2. Shirole, M., Kumar, R.: UML behavioral model based test case generation: a survey. SIGSOFT Softw. Eng. Notes 38, 1–13 (2013) 3. Surafel, L.T., Hong, C.: Modified firefly algorithm. J. Appl. Math. 39, 01–12 (2012) 4. Swain, R., Panthi, V., Behera, P.K., Mohapatra, D.P.: Automatic test case generation from UML state chart diagram. Int. J. Comput. Appl. 42, 26–40 (2012) 5. Yang, X.S.: Firefly algorithms for multi-modal optimization. Stoch. Algorithms Found. Appl. (SAGA) 2264, 169–178 (2009) 6. Yang, X.S., Xin, S.H.: Firefly algorithm: recent advances and applications. Int. J. Swarm Intell. 1, 36–50 (2013)