Automatic Test Cases Generation from Software Specifications
Total Page:16
File Type:pdf, Size:1020Kb
e-Informatica Software Engineering Journal, Volume 4, Issue 1, 2010 Automatic Test Cases Generation from Software Specifications Aysh Alhroob∗, Keshav Dahal∗, Alamgir Hossain∗ ∗School of Computing , Informatics and Media, University of Bradford amhalhro@ bradford.ac.uk, k.p.dahal@ bradford.ac.uk, m.a.hossain1@ bradford.ac.uk Abstract A new technique is proposed in this paper to extend the Integrated Classification Tree Method- ology (ICTM) developed by Chen et al. [13] This software assists testers to construct test cases from functional specifications. A Unified Modelling Language (UML) class diagram and Object Constraint Language (OCL) are used in this paper to represent the software specifications. Each classification and associated class in the software specification is represented by classes and at- tributes in the class diagram. Software specification relationships are represented by associated and hierarchical relationships in the class diagram. To ensure that relationships are consistent, an automatic methodology is proposed to capture and control the class relationships in a systematic way. This can help to reduce duplication and illegitimate test cases, which improves the testing efficiency and minimises the time and cost of the testing. The methodology introduced in this paper extracts only the legitimate test cases, by removing the duplicate test cases and those incomputable with the software specifications. Large amounts of time would have been needed to execute all of the test cases; therefore, a methodology was proposed which aimed to select a best testing path. This path guarantees the highest coverage of system units and avoids using all generated test cases. This path reduces the time and cost of the testing. 1. Introduction volved in developing software [7]. Software test- ing has two important purposes. First, it is com- Unified Modelling Language (UML) provides di- monly used to expose the presence of faults in agrams to help the software developer to repre- software. Second, even if testing does not reveal sent different aspects of design. It has become a any fault, it still provides increased justification standard modelling language for designing soft- and confidence in the correctness of the software ware. UML represents the system specifications [18]. The Category Partition Method (CPM) that could be used in software testing. The com- was developed by Ostrand and Balcer [19] to mon definition of software testing usually refers generate test cases from functional specifications to the testing of program code and not to the using the concept of formal test specifications. testing of models used in earlier development Several studies [2, 3] have been conducted which stages of the software development process, such focus on CPM. Recently, Chen et al. [14] en- as requirements engineering, analysis or design. hanced the CPM, by means of their choice re- Model testing could identify many faults earlier lation framework. Based on CPM, Grochtmann and could, hence, decrease repair costs. A crit- and Grimm [16] developed a similar but differ- ical component of testing is the construction of ent method – the Classification Tree Method test cases. However, software testing is an expen- (CTM). Classification trees have been used to sive and labour-intensive process; typically, test- construct test cases in the CTM. The absence ing consumes at least 50% of the total costs in- of a systematic tree construction algorithm is 110 Aysh Alhroob, Keshav Dahal, Alamgir Hossain the major limitation of this method. As a re- will work to its maximum capabilities. Path test- sult, users of this method are left with a loosely ing is a structural testing method that involves defined task of constructing a Classification Tree using software units to find every possible exe- (Tu). For complex specifications, this construc- cutable path. Time and cost are the main factors tion task could be difficult, and hence, prone to when testing efficiency, therefore, avoidance of human error. If a Tu. is incorrectly constructed, lengthy times in testing was the target set after the quality of the resultant test cases generated the legitimate test cases were obtained [1]. This from it will be poorly affected. This problem is paper extends the work presented in Alhroob, solved by Chen et al. [13] who use Integrated Dahal and Hossain [1] to select the best testing Classification Tree Methodology (ICTM). This path. This technique offers the best path that method helps with the identification of test cases covers most of the system units. via the construction of classification trees. How- The rest of the paper is organised as follows. ever, their tree constructed method is rather ad Section 2 presents the previous work in auto- hoc. This results in a variation of classification matic test data generation for UML. Section 3 trees constructed in CTM from one software presents a methodology to generate test data to tester to the next, according to his/her personal test class diagram relationships. Section 4 de- experience and expertise. A classification hier- scribes the classification tree concepts, whereas archy table (Hu) has been used in ICTM to al- the pruning method of duplicate sub-trees is leviate this problem. The hierarchy table helps outlined in Section 5. Section 6 covers the best to construct classification trees by capturing the testing path selection. Finally, conclusions and hierarchical relation for each pair of classifica- future works are presented in Section 7. tions. In ICTM [13], however, a manual method has been used in order to detect the classifications, 2. Previous Work associated classes and relationships. The man- ual process requires more human intermediation Test data are usually generated from the re- which can lead to more errors. Manual extrac- quirements or the code, while the design is tion of information from the software specifica- rarely concerned with generating test data. tions will also increase the cost of testing. In this Extensible Markup Language (XML) is used paper, we propose an approach for generating to express the constraints on data and de- test cases automatically from software specifica- tect the rules of software systems. Bertolino tions using a class diagram and representing the et al. [6] used the XML schema to analyse software constraints by OCL. After decompos- the system specifications and identify the func- ing the specifications to functional units, func- tional units. Categories are identified from func- tional units will be represented as a class dia- tional specifications. The authors [9] used XML gram. An XML schema mapping technique will schema mapping and category partition to iden- then be used to read the specification from the tify the related constraints and relevant val- class diagram. Transferring data from the XML ues for each category. In general, the test data to build a hierarchy table Hu. will reduce hu- generation can be extracted from those values man error in building the table. The construc- and constraints. tion of the Hu. is the step before building the Extracting the information from UML dia- classification tree. The paper also proposes a test grams allows the developer to test the system data refinement technique to discard duplicate before writing the code. Heuristic techniques sub-trees. The approaches are based on heuris- can be applied for creating quality test data. tic techniques for determining appropriate test Doungsa-ard et al. [15] proposed a GA-based cases for testing software. test data generation technique from specifi- Software testing is used to find as many cations. Test cases were generated from se- faults as possible so that a piece of software quences of triggers for Unified Modelling Lan- Automatic Test Cases Generation from Software Specifications 111 Figure 1. ICTM process guage (UML) state diagrams. Lia Bao-lin et al. in ICTM are manually entered. The manual pro- [4] constructed a scenario tree from a sequence cesses need more experience, more time and gen- diagram. The scenario path was obtained from erate higher costs. For large systems there are the tree and the attributes were extracted from many classifications and relationships; this re- the sequence diagram to generate test data au- quires more effort to input. To avoid the risk tomatically. Object Constraint Language (OCL) and effort, we propose a methodology to enable was used to describe the pre and post condi- the manual processes to be done automatically tions for the system to use its system specifica- without expert intermediation. Class diagrams tions. Sarma et al. [21] proposed a method to ex- will be used to represent the software specifica- tract this information from used case templates, tions. The proposed methodology is designed to class diagrams and data dictionaries. They also capture the specifications automatically to build presented an approach to transform the UML the Hu and Tu. The building of Hu and Tu au- sequence diagram to Sequence Diagram Graph tomatically, enables the generation of test cases (SDG) and provide the SDG with different in- in an efficient way. formation necessary to compose test data. The proposed methodology in this work pro- Dehla [23] proposed a technique to gener- duced full system coverage test cases, but other ate test data from UML sequence and state di- issues arose regarding the time needed to ex- agrams. The main specifications are extracted ecute the test cases, in addition to the cost. from the sequence diagram, while the remain- Peres et al. [20] introduced a good idea to ap- ing information derives from the state diagram. ply characteristics of software and of testing in Sequence diagrams do not provide all informa- test path selection. They used characteristics tion necessary to generate test data automati- in path selection strategies, such as complex- cally. Chen et al. [13] presented ICTM to create ity, testability and feasibility. They assigned a test cases from specifications, as shown in Fig- weight for nodes according to the lower predi- ure 1, via the building of Hu and Tu.