Conformity Behavior of Dissimilar Methods for Object Oriented
Total Page:16
File Type:pdf, Size:1020Kb
K. LOUZAOUUI Conformity behavior of dissimilar methods for object oriented constraint programming 212 Conformity Behavior of Dissimilar Methods for Object Oriented Constraint Programming Khadija Louzaoui Khalid Benlhachmi Department of Mathematics Department of Computer Sciences Faculty of Sciences, Ibn Tofail University Faculty of Sciences, Ibn Tofail University Kenitra, Morocco Kenitra, Morocco Abstract—This paper presents an approach for testing the number of test cases is infinite, therefore, testing is very conformity of overridden and overriding methods using expensive. So, how to select the most proper set of test cases? inheritance principle. The first objective of this work is the In practice, various techniques are used for that, some of them reduction of the test sequences by using only one generation of are based on the specification of the program under test using test data. The second result is the conformity testing of methods precondition, postcondition and invariant constraints. In this even if they are not similar: Our approach shows how the similarity partitioning can be used for testing not the similarity way the specifications by constraints in an object oriented behavior between methods but the conformity behavior of paradigm can be specified by formal languages as OCL [3] and subclasses for an object oriented model. JML [4], and are used for generating test data from formal specifications [5]. This software verification by constraints can In this work we use a mathematical modeling such as domain help for creating a mathematical modeling and building the partitioning and states graph for testing the conformity of parts of different classes of errors (equivalence partitioning). methods during inheritance operation. That is why our approach We present an approach for testing the conformity of an specifies all cases of conformity behaviors for similar and implementation from its specification [6,7] in object oriented dissimilar methods. programming. The main goal is the conformity testing of the (1) (2) Index Terms—Specification, conformity testing, robustness system :( overridden method: m , overriding method: m ) in testing, valid data, invalid data, test data generation, inheritance, inheritance operation. Indeed, the first objective is the constraint resolution. reduction of the test sequences by using only one generation of test data. The second result is the conformity testing of methods even if they are not similar [8]; The key idea is using I. INTRODUCTION directly similarity partitioning [9] for testing not the similarity Process of creating a program consists of defining a behavior between m(1) and m(2) but the conformity behavior problem, designing a program, building and analyzing [10,11] of m(1) and m(2). performances of a program. Software testing is a component of In this context, this paper introduces an optimizing this last phase, and is a way for checking if a program for approach to minimize the test sequences used for testing the specified inputs gives correctly and expected results. Software conformity of an overriding method in object oriented models. testing can be defined that as: “A process of executing a The main idea of this work is the use of a technique that program with the goal of finding errors” [1]. The goal of generates test data by exploiting the similarity partitioning. testing is systematic detection of different classes of errors by Indeed, it is important to use a mathematical modeling such as using a model of the program under test or analyzing the domain partitioning and state graph for testing the conformity internal structure of this program. So software can be tested in of methods during inheritance operation. That is why our two ways: testing software with the knowledge of the internal approach specifies all cases of conformity behavior for similar structure and coding inside the program (white box testing), the and dissimilar methods. second method is a testing based on output requirements and Most works have studied the problem of relating types and without any knowledge of the internal structure or coding in subtypes with behavioral specification in an object-oriented the program ( black box testing). paradigm. These proposed works show how the contracts are Indeed, testing means that one inspects behavior of a inherited during method overriding and how the testing process program on a finite set of test cases (a set of inputs, execution can use the formal specification. In [6,7], we have presented preconditions, and expected outcomes developed for a the definition of a formal model of constraint, illustrating the particular objective, such as to exercise a particular program relationship between preconditions, postconditions and path or to verify compliance with a specific requirement [2]) invariants of methods, and we have formalized a generic for which the evaluated inputs always exist. Theoretically, the constraint of a given individual method of class that contains all constraints into a single logical predicate. The given model Revue Méditerranéenne des Télécommunications Vol. 5, N° 2, June 2015 Mediterranean Telecommunication Journal K. LOUZAOUUI Conformity behavior of dissimilar methods for object oriented constraint programming 213 translates algebraically the contract between the user and the logical property of the pair (x,o) (x is the vector of parameters called method. (x=(x1 ,x2 ,…, xn)) and o is the receiver object) such that: In [8], we have developed a basic model for the concept of H( x , o ): P ( x , o ) [Q(x,o) Inv(o)],(x,o) E I methods similarity, the test is based only on a random c generation of input data. In [9], we have generalized the basic Where Ic is the set of instances of the class C and E the set of input vectors of m. model of similarity using analysis of partition and formal proof. In [12], the authors propose a randomly generation of Class C test data from a JML specification of class objects. They classify the methods and constructors according to their m (…) P , Q , Inv signature (basic, extended constructors, mutator, and observer) and for each type of individual method of class, a generation of {…} test data is proposed. In [13], the paper describes specially the Precondition Postcondition Invariant of C features for specifying methods, related to inheritance specification; it shows how the specification of inheritance in JML forces behavioral sub-typing. Fig. 1. Constraints of the method m( ) In [14], the authors treat the problem of types and subtypes Indeed, the invocation of a method m is generally done by with behavioral specifications in object-oriented world. They reference to an object o and consequently, m is identified by present a way of specification types that makes it convenient to the couple (x,o) . The logical implication in the proposed define the subtype relation. They also define a new notion of formula means that: each call of method with (x,o) satisfying the subtype relation based on the semantic properties of the the precondition P and the invariant before the call, (x,o) must subtype and super-type. In [15], they examine various notions necessarily satisfy the post-condition Q and the invariant Inv of behavioral sub-typing proposed in the literature for objects after the call. In the context of this work, we assume that the in component-based systems, where reasoning about the events object which invokes the method under test is valid (satisfying that a component can raise is important. the invariant of its class), thus, the objects used at the input of The work presented in this paper can reduce the number of the method under test are generated from a valid constructor. test cases by adapting the similarity partitioning [8,9] to the This justifies the absence of predicate Inv of the object o before coverage of conformity behaviors of the system (m(1), m(2)). the call to m in the formula H (Figure 2). Indeed only one generation of the test data is necessary to deduce conformity of overridden and overriding methods. m In this work we propose a conformity testing of methods even Input: P(x,o) Output: Q(x,o) Inv(o) if they are not similar and we use a graph of states for modeling the evolution of the system (m(1), m(2)) independently from the test data generation (In [10] we generate data for testing the similarity between methods, and then we generate Fig. 2. Simplified specification of a method m( ) data for testing the conformity of the original method m(1): if the methods are similar we can deduce the conformity of III. CONFORMITY TESTING AND SIMILARITY MODEL IN overriding methods; if they are not similar we are unable to INHERITANCE progress in the test process). This paper is organized as follows: in section 2 we present A. Conformity constraints the formal model of constraints based on methods The formal model of test proposed in [6,7] defines the specification, in section 3 we define the theoretical aspects of notion of method validity in a basic class and constitutes a way the conformity test process, and we show why the model of to generate test data for conformity. In a conformity test, the similarity concept is necessary, in section 4 we present how the input data must satisfy the precondition of the method under similarity partitioning can be used to define the conformity test. In this context, we are particularly interested in valid input behaviors and to generate test data during inheritance values (i.e. the pairs (x,o) that satisfy the precondition P). operation. The section 5 proposes a mathematical modeling The conformity test for a method means that if a with graph of states for the system (overridden method, precondition is satisfied at the input, the postcondition and the overriding method). Finally, in section 6 we describe our invariant must be satisfied at the output.