Ocl Expression For Pre And Post Conditions

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

Abstract— Manual software testing is both an expensive and time consuming activity, requires proper planning and resource. We proposed a method to automate the process of test case generation. This proposed technique reduce time and increase the reliability of the software testing processes. The main criteria of software testing is to generate test cases. Our methodology consist of transforming the state diagram (UML) into finite state machine (DFA / NDFA) where each node represent state and the arrow connecting the states represent transition. The nodes store state information and arrows maintain trigger information which is necessary for state transition. This state information is mined to build test case. The proposed technique attains sufficient test coverage without increasing the number of test cases. It also achieve many important coverage like transition coverage, transition pair coverage, and provides state coverage.

Keywords— Software Testing; UML; State diagram; Test Case. (key words)

Introduction

Software testing includes executing a software on a group of test cases and verify the particular results with the expected results. The important task of software testing is to assure the quality of software product. Existing test sequence generation methods are costly, time consuming and also with less testing coverage. This may cause the following critical issues:

The project budget may be increase, particularly in the large software systems. Testing may take about 50% of total budget [1].

It may cause a delay of developing software system phase.

Some test cases may not be covered (less coverage) and tested properly, In future which may causes to many known flaws.

A well tested software package will be checked by the client before acceptance. However, in object-oriented environment the designing and implementation of software is complicated because it has to deal with important object-oriented concept like polymorphism, inheritance, encapsulation, dynamic binding etc. This makes software testing complicated and more chance to error-prone.

In software engineering a test case is a set of criteria or variable under that a tester will validate whether the software system or an application is working properly or not. Usually software developers may not have enough time to create test case after coding phase to test their code. This problem can be solved by generating test case before the coding phase. It will help the developers to test their software after the end of coding [2]. Generation of test cases using UML model are one of the most significant method. This method has many advantages it can cover the issues raised by object-oriented paradigm. However, test case generation from UML model is not an easy task it is the most challenging task. Because test case needs so many parameters like input values, pre- and post-condition of the input values, and the expected output. Several researchers propose to way out of this problem, but that increase the complexity of test case generation effort.

In this paper we proposes a technique to generate test case automatically using UML models. UML State diagram is used as a source for test case generation. Generated test suits achieves many important coverage like transition coverage, state coverage, transition pair coverage etc. State diagram alone is not sufficient to generate test data, some more different parameters that is input values, pre- and post-condition of the test case, and expected output is needed. For that we can take the help of other UML model like use case diagram.

Related works

Several research attempts have been proposed for test case generation under various circumstances, mainly scenario based, path oriented, model based, goal oriented approaches. Scenario-based test case based on concurrent approach with concurrence coverage criteria. Path-oriented testing based on static and also dynamic flow of the software. Static path testing is based on symbolic execution, and dynamic path testing done by evaluation of running time of executing program. Model based technique is deal with different UML models such as state-chart, sequence diagram, object diagram, activity etc. Goal oriented technique identify test case which covers a selected goal such as a branch or statement.

Many research have been going to generate test case based on the specifications.

Monalisa [3] have proposed a technique which used UML sequence diagram to generate test case. They transformed the UML case diagram to sequence diagram graph (SDG), and they generate test case based on two coverage criterion.

Novada Haji Ali and Sufian Idris [4] they design an assessment system for UML diagrams. They developed a tool named UCDA that can produce list of comments on a UML diagram.

J. Hartmann, M. Vieira, H. Foster, and A. Ruder [5] provides a technique based on the interaction between system and user, that information is used to generate automatic test suit. In this process use cases textual description is converted into activity diagrams.

Ranjit Swain, Prafulla Kumar Behara at al [6] they used function minimization technique and construct test case automatically from UML state chart diagrams. First the diagram is prepared then the diagram is traversed using DFS to select associated predicates. After that initial dataset is guess and conditional predicates are transformed to generate test cases.

Bertolino and Basanieri [1] [7] they proposed a technique which describe how to generate test cases manually using Use Case and Interaction diagrams. The main objective of this technique is to check the pre-tested software modules are interact correctly at integration testing or not. In sequence diagram the different component interacts with each other through message passing. This message information is used with category partition method (CPM) to generate test case manually.

A novel approach proposed by M.Lettrari and J. Klose [9]. They focus on real time system only.

P.Tonella and Potrich [10] they used reverse engineering technique on UML sequence diagram to generate test case.

Now UML becomes most widely used language. For model based test case generation several researchers are focused on different UML models like sequence diagrams, use-case diagrams, state-chart diagrams, class diagram etc.

Proposed Approach

In the propose approach we transform a given state diagram

into a finite state machine (FSM). Each node in FSM stores necessary information for test case generation. The important feature for test case generation are stored in node of FSM, these important feature collected from use case diagram including pre and post- conditions are expressed using Object Constrained language (OCL). Finally based on different coverage criteria FSM is traversed to generate the suitable test case. An example of ATM is given below to show, how to determine pre and post condition of ATM system using use case diagram.

Pre- and Post- Condition of Use Case

Pre-condition:- Before creation of use case diagram it is the necessary state that must be present to the system.

Post-condition:- It is a list of possible states that may be exist just after a use case has finished.

Example 1.

Bank System

Service Admin

Withdraw Cash

Customer

Security Admin

Fig. 1 Use Case diagram of money withdraw from a bank account using ATM

Pre-conditions of Cash Withdraw

The customer with valid ATM card.

Active network connectivity with the Bank System must exist.

There must be sufficient cash in the ATM to withdraw.

Cash withdrawal option must be enable.

Post-conditions of Cash Withdraw

If the customer enters correct PIN number and the customer's account balance is greater or equal to the requested amount, then only the customer can able to withdraw the requested amount and the same amount must be deduced from the customer’s account.

If the customer enters the wrong PIN three times, the card should be retained.

The ATM card will be returned back to the customer if the customer wants to withdraw excess money.

OCL expression for pre and post-conditions

Object Constrained Language (OCL) is a declarative language for describing rules that apply to Unified Modeling Language (UML). It was developed at IBM and presently part of the UML standard [13]. OCL provides expressions that are not ambiguous like natural language. For graph- based model it is a navigation language.

Transformation of State diagram to FSM.

UML state diagram provide a way to model the behavior of the system by analyzing how the state of the system changes in response to input data.

Every software system has something we called it state. Software state consists of the current value of all the variable in program at any given moment in time. In the case of object oriented system the state of the system is stored within the object in the system, and each object has its own state which is stored in the object’s variables (class fields). The essence of running a computer program is changing the software from one state to another. Finite state machine (FSM) used to model the software system conceptually. FSM has fixed number of states and the system is always any one of the fixed number of states when it is running. As computation progress the FSM transition from one state to another. Each state machine can receive input and it possibly produces output during state transition upon entering a state, upon leaving a state or even within a state. FSM is two type Deterministic and Non-deterministic. In practice of writing software model we try to minimize non-determinism since non-deterministic program could produce different result each time, they run with same input. Therefore we would like our enterprise application to be deterministic.

Definition of DFSM:

A deterministic finite automata consist of 5-tuple

M=Q,, , q0, F

Where

Q  Is finite set of all states i.e. set of all FSM nodes defining various conditions of operation scheme; each node signifies an event.

  Is finite set of input symbol, transition is happened for these inputs.

  Transition function, it describe from where to where states are moving for a particular input.

q0  Operation begins from this state, means it is initial state.

F Operations will terminate to this state. It may be single or set of node.

We define operation scheme (OpScm) as 4 tuple,

OpScm: <SId, BeginState, MsgSet, NextState>

SId  A unique id for each operation scheme.

BeginState  Is a starting point of scheme.

TransitionSet It include set of all events that happens in an operation scheme.

NextState System enters to this states after completion of an operation scheme.

It may happen that a DFSM has a single begin state but multiple end state which depends on various operation scheme.

Four tuple is used to represent an event in a "TransitionSet".

aEvent :<tr, S, R, G>

tr  Value or name of the trigger for which transition occur.

S  Current node/state which sends trigger.

R  Next node/state where transition occur form current node.

G  It is a guard condition used to decide which event will occur next.

Example2. Fig. 2 shows a state diagram of one session ATM system.

CardRead[No]/Eject

Reading Card (S1)

Reading Pin (S2)

An

CardRead[Yes]

Ay

PinRead[No]/Eject

Bn

By

PinRead[Yes]

CancelPressed/Eject

Choosing Transaction (S3)

Cn

Ac

Cy

AnotherChoice

TransactionChoosen

Performing Transaction (S4)

Dy

TransactionSuccess

Ejecting Card (S5)

(a) State diagram of one session ATM system.

An

Nf

Cn

Cy

S5

S4

S3

S2

S1

Dy

By

Ay

AC

Nl

Bn

(b) DFSM for the state diagram (a)

TABLE I

 Is defined by following State Transition Table

Ay

An

By

Bn

Cy

Cn

Dy

Ac

S1

S2

S5

S2

S3

S5

S3

S4

S5

S4

S5

S3

S5

OpScm1: Nf ï‚®S1ï‚®S5ï‚®Nl

OpScm2: Nf ï‚®S1ï‚®S2ï‚®S5ï‚®Nl

OpScm3: Nf ï‚®S1ï‚®S2ï‚®S3ï‚®S5ï‚®Nl

OpScm4: Nf ï‚®S1ï‚®S2ï‚®S3ï‚®S4ï‚®S5ï‚®Nl

OpScm5: Nf ï‚® S1ï‚®S2ï‚®S3ï‚®S4ï‚®S3ï‚®S4ï‚®S5ï‚®Nl

OpScm6: Nf ï‚® S1ï‚®S2ï‚®S3ï‚®S4ï‚®S3 ï‚®S5ï‚®Nl

(c) List of possible operation scheme from DFSM

Test Case Generation

A state diagram provides a way to model the behavior of the system by analyzing how the state of the system changes in response to input data. So, the test set is essential to detect faults during the state of an object is changes from one to another. It is necessary to cover all possible combination of paths from start to end node of DFSM to ensure maximum coverage.

Algorithm TestCaseGeneration

Input: DFSM Graph

Output: TestSet T

Notation: Nf, Nc, Nn, Nl are the first, current, next and last node respectively.

Testcase Γ= {, s, r, G,}

Where

 Pre-condition of node/state.

s Set of input value/ trigger for senderNode.

r Set of output value/ resultant node after transition.

G Set of guard condition for transition.

 Post-condition of node/state.

The event E­c corresponding to current node Nc is

E­c= (tr, S, R, G).

Steps:

Take all paths = 1, 2,…..,n from the start to end node in DFSM.

FOR each path i   do

N­c← Nf

Γi ← ɸ //Initially testcase for the operation

//scheme OpScmi will be empty.

Nc ← Nn //Move to next node of OpScmi

WHILE (Nc ≠ Nl)

E­c= (tr, S, R, G) //The event of Nc.

IF G = ɸ THEN

Γ= {, s, r,}

Γi = Γi U Γ

ENDIF

IF G ≠ ɸ THEN

Γ= {, s, r, G,}

Γi = Γi U Γ

ENDIF

Nc ← Nn+1 //Go to next node of Nn //on the path i.

Γ = Γ U Γi

ENDWHILE

Determine the final output r and  from the operation scheme OpScmi stored in Nl.

Γ= {, s, r, G,}

T← T U Γ //Add the test case to test set

ENDFOR

RETURN (T)

STOP.

TestSetGeneration starts by considering all paths in DFSM from start to end node. A path essentially corresponds to an operation scheme. We find out the test case for all possible paths from start to end node and integrate them one by one to generate final TestSet T.

The main strategy of testing is to detect certain type of fault that can be called as fault model [12]. Our testing technique is based on following fault model.

Transition fault: Generally in a state diagram the state of an object is changed from one to another when some certain conditions are true. In this state transition there may be several faults like, incorrect response or state change to an input, correct input pass to a wrong state, incorrect input pass to a right state, input passed with improper or incorrect condition or guard value.

Scheme fault: Each operation scheme represents to all possible sequence of transition path in state diagram. For a particular operation scheme, transition of state may not adopt a particular route because of inappropriate guard statement, or abnormal termination etc.

conclusion

It has been proved that different UML models are effectively used to generate test cases. This paper suggests a technique to achieve test cases based on UML state diagram. This approach will help software developer and tester to start the testing process quickly in the software development life cycle. The prerequisite information like pre and post-condition is collected from use case diagram and expressed in terms of Object Constrained Language (OCL 2.0) [11]. The best part of this approach it does not require any alteration in the UML models to generate test cases. DFSM is basically a graph based methodology and our proposed algorithm enumerate all possible path to generate test case. In worst case with n nodes the time complexity of the proposed algorithm is O(n2) which is significantly less and this suggests that our technique is capable enough to handle big enterprise project efficiently. We have concentrated on use case and state diagram and this approach could be extended for Nested State Charts and other UML diagrams for further research.

acknowledgment

We would like to sincerely acknowledge the en-courageous efforts of our Faculty members. Special thanks to our program manager, Dr. L. Jeganathan and our coordinator Dr. E.S.F. Najumuddin for giving us the opportunity for learning.



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now