Test Case Design Using Conditioned Slicing of ...

10 downloads 5264 Views 289KB Size Report
2, May 2009. 117. Test Case Design Using Conditioned Slicing of. Activity Diagram. Mitrabinda Ray, Soubhagya Sankar Barpanda, Durga Prasad Mohapatra.
POSTER PAPER International Journal of Recent Trends in Engineering, Vol. 1, No. 2, May 2009

Test Case Design Using Conditioned Slicing of Activity Diagram Mitrabinda Ray, Soubhagya Sankar Barpanda, Durga Prasad Mohapatra Department of Computer Sc. & Engineering, National Institute of Technology, Rourkela, India Email: {mitrabindar-cs801, Soubhagyab, durga}@nitrkl.ac.in

Abstract— For testing software, test case generation is the most important part. The automation of specification based test case generation needs formal or semi formal specification. As a semiformal modeling, UML is widely used to describe analysis and design specification by both academia and industry. Thus UML models become the sources of test case generation naturally. This paper proposes a method to generate test cases from UML activity diagrams. We have proposed conditioned slicing as a general slicing framework for test case generation from activity diagrams. Our method first builds a flow dependence graph from an ordinary UML activity diagram and then applies conditioned slicing on a predicate node of the graph, to generate test cases. It minimizes the number of test cases generated while deriving all practically useful test cases. The effectiveness of a test case is based on how well the test covers and exercises the modeled behaviors. Our proposed method satisfies high path coverage criterion. Index Terms—UML Activity Diagram, Test Case Generation, Conditioned Slicing, Testing using Slicing.

I. INTRODUCTION Testing is an important part of quality control in the Software life-cycle. As the complexity and size of software grow, the time and effort required to do sufficient testing grow. Manual testing is time-consuming and error -prone. Therefore it is pressing to automate the testing effort. The testing effort can be divided into three parts: test case generation, test execution, and test evaluation. The latter two parts are relatively easy to be automated provided that the criteria for passing the tests are available. Test cases are generally designed at the specification or code level. In this paper we are presenting a novel approach for generating test case at the design level by the help of conditioned slicing of UML model. This has the advantage of allowing test cases to be available early in the software development cycle, thereby making test planning more effective. UML Activity Diagram is developed using elements that are divided into two groups; Nodes and Edges. The OMG’s UML 2.0 super structure specification defines three types of Nodes: Action nodes, Object nodes and Control nodes. The edges are defined as the transitions that represent control flow and data flow between nodes. An Action

node is a fundamental unit of executable functionality in an activity. Actions have incoming and outgoing edges that signify control flow and/or data flow from and to other nodes respectively. A compound activity is a node, which is a condensed set of nodes and edges depicted in a separate diagram. An Object node is a node that indicates an instance of a particular classifier that may be available at a particular point in the activity. A Control node is used to coordinate the flow of data and control between other nodes. “Fig. 1” shows an example of activity diagram representation for ATM Withdraw Cash activity. In this figure accept amount is an action. Actions are linked together using activity edges. An action may have several incoming and outgoing activity edges. Activity edges are annotated by labels placed near arrows. UML 2.0 allows using an element called a note, for incorporating additional information in an activity diagram. Notes are shown with dog-eared rectangle symbols that are linked to activities through dashed lines. In this paper we are numbering the predicates and expressions on activity edges and notes for establishing the correspondence between the Activity Diagram. We proposed a method to generate test cases automatically by conditioned slicing of activity diagram. Till now application of conditioned slicing is used in program compression [2], debugging and reverse engineering [3]. But no work has been reported for testing ObjectOriented programs. In this paper our objective is to minimize test cases that cover the maximum paths. It is possible by slicing the activity diagram on the basis of applying pre-conditions on control nodes. In our approach, first we select a conditional predicate on an activity edge during the execution of an activity diagram with a random input data set. Subsequently, we are checking each path in the flow dependency graph by slicing the path and checking the simplicity of the path. The remainder of the paper is organized as follows. In the next section we give some basic definitions and the background for the rest of the paper. Our proposed slicing technique is described in section III. Section IV is comparison with related work and section V is conclusion.

II. DEFINITIONS AND BACKGROUND In this section, we present a few basic concepts, notations and terminologies associated with the

117 © 2009 ACADEMY PUBLISHER

POSTER PAPER International Journal of Recent Trends in Engineering, Vol. 1, No. 2, May 2009

5

intermediate program representations. These concepts and terminologies are later used throughout the discussion. Definition 1 Flow Dependency Graph (FDG)

Definition 2 Dependency Edge If a node i, i∈ N is either data or control dependent on node j, j ∈ N , then there can be an edge in FDG from node i to node j called a dependency edge. Definition 3 Dependency Path Given an FDG, a dependency path F from some node vi to some other node vk is a sequence of nodes and edges in the FDG from vi to vk.

Accept Amount

6

9

It is a directed graph . FDG= {N, D} where N is the set of nodes and D is the set of edges. Here N={E,R}, where E is the set of e-nodes. An e-node, e ∈ E represents an activity edge of the corresponding activity diagram with its attributes such as guard condition and label. R is the set of r-nodes. An r-node, r ∈ R represents a note in the activity diagram. Edges of FDG called dependency edges represent dependencies among nodes. Here there is no difference between control and data dependency. The sub graph of FDG corresponding to the activity diagram in “Fig. 1” is shown in “Fig 2”. UseVar(x) is the set of all nodes in FDG that use the value of variable x. AllotVar(x) is a set of two types of nodes of FDG. AllotVar(x) = {F, C}. F is the set of all rnodes that define the variable x. Nodes of type C are the following if x is used to specify guards in more than one e-node such e-nodes are also treated as Allotvar(x). For example in “Fig. 2” Allotvar(a)={4,5} and AllotVar(b) ={9,10,11}.

Display Transaction Menu

4

4. [a> 500]

10 11

7

8

12

13

Figure2. Flow Dependence Graph (FDG) of Activity Diagram of “Fig. 1”.

Definition 4 Conditioned Slicing It was first introduced by Canfora [1]. It forms a bridge between the two extremes of Static and Dynamic slicing. Conditioned slicing is a technique for identifying those statements and predicates which contribute to the computation of a selected set of variables when some chosen condition is satisfied [1, 2, 6]. The set of initial states of the program that characterize these executions is specified in terms of a first order logic formula on the input variables of the program. Conditioned slices can be identified by using symbolic execution techniques and dependence graphs [1]. In “Fig. 3” student’s overall mark is the input and the output is result (pass, fail) and the grade. Suppose the grade is the variable of interest and the program execution of interest is defined by the condition C = (mark >=35 ^ mark < 40). The conditioned slice for the criteria (grade, 11, C) is only one statement as shown in the “Fig. 3”. Definition 5 Slice Domain

6.[r = res - a] 5. [a= 0 ] Find Balance

Validate PIN

10. [ b 0 ] Dispaly Insufficient Balance

III CONDITIONED SLICING OF ACTIVITY DIAGRAM

Display Cash Available

13.[res = r ] 12. [bal = b]

Update Account

Update Cash Reserve

Print Passbook

Figure 1. An Activity Diagram Modeling an ATM Withdraws Cash Scenario.

In our approach, the slices of the activity diagram shown in “Fig. 1” are generated using the flow dependency graph and conditions. We compute slices corresponding to each conditional predicate present on activity edges and test cases are automatically generated with respect to each slice. The Conditioned slicing using ConSUS slicing tool [4] are used to test the dependency path in FDG. A slice domain is surrounded by a boundary. A boundary might consist of several segments and each segment is called a border. For example in “Fig. 1”, the condition (b > 1000) defines a border.

118 © 2009 ACADEMY PUBLISHER

POSTER PAPER International Journal of Recent Trends in Engineering, Vol. 1, No. 2, May 2009

1.main(){ 2. int mark; 3. char grade, *result; 4. scanf(“%d”, &mark); 5. if (mark < 35) {result=”FAIL” ; grade =’F’ ;} 6. else { result=”PASS” ; 7. If (mark < 40) grade =’E’ ; 8. else{ If (mark < 50) grade =’D’ ; 9. else { If (mark < 60) grade =’C’ ; 10. else { If (mark < 70) grade =’B’ ; 11. else grade = ‘A’ ;}}}}} ( Student’s final year result program P ) grade =’E’ (Conditioned slice of P with respect to C (grade, 11, C))

Figure 3 Traditional Static slice and Conditioned slice of student’s Result Program.

The domain space for the variable b is the set of all integers. The condition turns out to become false for values (b 1000) which corresponds to e-node 11 of FDG in “Fig. 2”. A partition P= {D1, D2…DN} of the input domain D is produced. The partition has the property that the behavior is uniform on each Di [5]. The conditioned slice denotes the condition that the input is in the domain Di. For example test the sub domain when the balance is greater than 1500 and amount to be drawn is maximum Rs. 500. This condition is first converted to first order predicate logic (FOPL). In FOPL the condition C0 is { ∀ a, b, r (AMOUNT(a) ^ BALANCE(b) ^ RESERVE(r) ^ ~GT (a, 500) ^ GT (b, 1500) ^ GT(r, a))}. The conditioned FDG with respect to the condition C0 is shown in left part of “Fig. 4”. This reduced FDG is a uniform graph. The simplicity of this graph suggests that the behavior is uniform on this sub domain. A very few number of tests are required here. The test data is any input data satisfying the constraint in condition C0. As the slice is simple, it is helping the tester to easily determine the correctness. The partition analysis helps to cover the complete path by reducing the FDG to a simple one. Let I0 is the initial data set [400, 1600, 500] which is chosen randomly satisfying the constraint in C0. If the sub domain is not uniform, then we will not get simple path [5]. In such situations, ConSUS [4] can be of further assistance, by computing the simplest path conditions applicable. For example, let the condition C1

is { ∀ a, b, r (AMOUNT (a) ^ BALANCE (b) ^ RESERVE( r ) ^ ~GT (a, 500) ^ ~GT (b, 1500) ^ GT(r, a)}. The conditioned FDG with respect to the condition C1 is shown in right part of “Fig. 4”. It is not uniform as the paths are not simple. The sub domain is needed to be refined further. In this case ConSUS[4] can be further assistance by computing the simplest path conditions: C 1.1: C1 ^ ~GT (b, a+1000) C 1.2: C1 ^ GT (b, a+1000). Now the paths are simple. This suggests all complete path coverage by partitioning the input domain D. The random data sets satisfying the constraints in condition C 1.1 and C 1.2 are [400, 1300, 500] & [400, 1450, 500]. IV. COMPARISON WITH RELATED WORK

In this section we provide a comparison of our work with other UML based test generation methods. To the best of our knowledge, no work has been reported in the literature that discusses application of conditioned slicing on Activity Diagram for test case generation. We have gone through several approaches for generating test cases from UML Activity Diagram [7-10], but most of them

119 © 2009 ACADEMY PUBLISHER

POSTER PAPER International Journal of Recent Trends in Engineering, Vol. 1, No. 2, May 2009

V. CONCLUSION We have presented an execution based schema to generate test cases using conditioned slicing of activity diagram. We generate conditioned slices and slicing criteria based on the Flow Dependence Graph to make it applicable to Activity Diagram. Construction of Flow Dependence Graph is static in our approach. We are continuously partitioning the input domain and slicing the FDG till getting a simple path. It helps to automatically generate test data, which can be used by a tool to automatically test a program. Our approach achieves complete path coverage by boundary testing criterion and dividing the test input domain into sub domains using conditional predicates.

5

5 9 9

11

10 11

12 12

FDG(C) with respect to the condition C0

FDG (C1) with respect to the condition C1

REFERENCES

Figure 4. Reduced FDG by applying Conditions C0 & C1

tend to purpose only a conceptual idea and not guarantee the complete path coverage. Currently there is no work on the implementation of conditioned slice in UML model. Linzhang [7] proposed a method to derive test scenarios directly from UML Activity Diagram. They generate test scenarios using a DFS traversal on the activity diagram considering it as a graph. Their approach do not capture actual dependency of the system. As it only considers the static structural information of the model, run time behavior due to data dependency are not captured. We are getting better performance by considering conditioned slicing and partition analysis. By the help of it, we are able to consider run time behaviors due to data dependency on the flow dependence graph of the activity diagram. Many of the UML based test generation methods reported in the literature do not generate test cases. Instead, they were successful up to the extent of generating valid test scenarios. Test scenarios are test requirements or test sequences (like possible execution sequences of use cases, message sequences, event sequences etc) that must be satisfied or covered during testing. The exact value of test data (or test case) for which these test scenarios are tested is not addressed in many related works. Kim [10] proposed a method to generate test scenarios for a concurrent system. They first build an I/O explicit activity diagram from an ordinary activity diagram and then transforms it to a directed graph, from which test cases for initial activity diagram are derived. But the limitation is that they did not find the total number of input sets that is required for achieving complete path coverage. Since we are using partition analysis on the input domain, it helps us to decide the total number of input sets required for full path coverage. we are partitioning the input domain till getting a simple path.

[1] G. Canfora, A. Cimitile, and A. De Lucia, “Conditioned Program Slicing,” Information and Software Technology, vol. 40, no. 11-12, 1998, pp. 595-607. [2] Andrea. De. Lucia and Anna Rita Fasolino, “Understanding function behaviors through program slicing,” In 4th IEEE International Workshop on Program compression (Berlin, Ger-many, Mar. 1996) , IEEE Computer society Press, Los Alam-itos, California, USA, pp. 9-18. [3] Canfora G.1, Lucia A.D. & Munro M. Source, “An integrated environment for reuse reengineering C code.” Journal of System and Software 42 (1998), pp.153-164. [4] Daoudi M, Danicic S., Howroyd J, Harman M, Fox C, Ouarbya L and Mard M, “ConSUS: A scalable approach to conditioned slicing,” Proceedings of the Ninth Working Conference on Reverse Engineering (WCRE'02), pp-109. [5] R.M. Hierons, M. Harman, C.J. Fox, M. Daoudi, and L. Ouarbya, “Conditioned slicing supports partition testing,” The Journal of Software Testing, Verification and Reliability (2002), 121, pp. 23-28. [6] Sebastian Danicic , De Andrea Lucia , Mark Harman, “Building Executable Union Slices using Conditioned Slicing,” 12th IEEE International Workshop on Program Comprehension (24-26 June, 2004, Bari, Italy), pp. 89. [7] W. Linzhang, Y. Jiesong, Y. Xiaofeng, H. Jun, L. Xuandong and Z. Guoliang, “Generating test cases from UML Activity Diagram based on gray-box method,” In Proceedings of the 11th Asia-Pacific Software Engineering Conference (APSEC04), pp 284-291.IEEE, 2004. [8] Mingsong Chen, Xiaokang Qiu, Wei Xu, Linzhang Wang, Jianhua Zhao and Xuandong Li, “UML Activity DiagramBased Automatic Test Case Generation for Java Programs,” The Computer Journal (2007),

120 © 2009 ACADEMY PUBLISHER

in Press.

[9] Chen, M., Qiu, X., Li, X., “Autometic test case generation from UML Activity Diagram,” Proceedings of the 2006 international workshop on Automation of software test, pp 2-8. [10] Kim Hyungchoul, Kang Sungwon, Baik Jongmoon, Inyoung Ko, Test Case generation from UML Activity Dia-gram, Eight ACIS International Conference on Software Eng-ineering, Artificial Intelligence, Networking, and Parallal / Distributed Computing (SNPD 2007) Volume 03. pp 556-561. IEEE, 2007.

Suggest Documents