Proceedings of the International Conference on                                                                                                    C-24
Electrical Engineering and Informatics
Institut Teknologi Bandung, Indonesia June 17-19, 2007
                    Automatic Generation of Test Cases from Use-Case Diagram
                                            Noraida Ismail 1*, Rosziati Ibrahim2, Noraini Ibrahim1
                                                     1
                                                  Faculty of Information Technology and Multimedia,
                                                 2
                                                 Research Management and Innovation Center (RMIC)
                                             University of Technology Tun Hussein Onn Malaysia (UTHM).
                                                        Parit Raja, Batu Pahat, Johor, Malaysia.
                       Intelligent searching techniques have been developed in order to provide a solution to the issue of finding
               information relevant to the user needs, and the problem of information overload - when far too much information is
               returned from a search. We employ this technique to introduce an automatic tool which used to generate the test cases
               automatically according to the system’s requirement. The tool uses two steps for generating test cases. First, the system’s
               requirements are transformed into a Unified Modeling Language (UML) Use-case Diagram. Second, the test cases will be
               automatic generated according to the use cases respectively. In the workspace, the ToolBox is used in order to ease the
               drawing of the use-case diagram. As well as allowing a user to layout the requirements of the system via a use-case
               diagram in the provided workspace, a user also may type-in the properties for each of the use cases used. Once the use-
               case diagram has been finalized, it can be save for further used and modification. The engine of the tool will take the use
               cases from the use-case diagram and search the query string (keyword) used in the tool’s library. The searching engine
               uses both search keyword and additional information of the use-case diagram. This combination will result in improving
               data retrieval performance. Once the use case used matches the keyword inside the tool’s library, the engine will
               automatically generate its respective test cases according to its use case.
               Keywords: Intelligent Searching Engine, Artificial Intelligence, Information Retrieval, Automatic Generator, Use-Case
               Diagram
        1. Introduction                                                                  This paper discusses on idea where this crucial part
                 Intelligent search technique has been proposed in             of SDLC is allowed to be done at early stages and proposes
        order to soft the issue of information overload – when too             an automatic testing tool to validate either the system fulfills
        much information is returned from a search (10). On the                its requirements or not. This paper is organized as follows:
        other hand, it is also help to provide a solution for reducing         several introductory related works are described in Section
        gap between what people really want to find, and the actual            2. Section 3 discusses the system’s requirements. An idea on
        query strings they specify. This issue occurs because of same          how to convert the use cases into test cases also will be
        terms may have different meanings in different places. In              given in Section 3. Section 4 discusses our tool in details, in
        order to overcome both problems, the information retrieval             particular on how to retrieve data from the database using
        engine should intelligent enough to understand the user                the engine of the tool. In Section 5, we summarize our work
        needs. The combination of query string specified and                   and suggest future work.
        additional information will help the information retrieval
        engine to make a judgment for returning the likely relevance           2. Related Work
        search result (7).                                                              There are several discussions on how using use
                                                                               cases may help testing process to be done early in the
                  Therefore, we employ this technique into our tool,           development lifecycle. Jacobson et al. (4) explained tests can
        automatic generation of test cases from use case. This tool is         be derived from use cases in three types: First, tests of the
        used to generate the test cases automatically according to the         expected flow of event; second, tests of unusual flow of
        system’s use cases. These test cases are important to be used          events; and third, test of any requirements attached to a use
        in analyzing and validating the requirements of the system.            case. Unfortunately, Jacobson et al. (4) did not discuss on
        As an indispensable aspect in software development                     how to choose test cases and how to know when you are
        practices, software testing is important to reveal errors in the       done.
        software and to ensure that software fulfills its requirements.
        In the traditional practices of software development lifecycle                  Binder (8), Heumann (6) and Wood et al. (3) derive
        (SDLC), testing software is done at the later stage (analysis          test cases directly from requirements in natural language.
        – design – prototyping – testing). From the empirical studies,         Wood et al. (3) state that the most integral part of use case
        delaying the software testing at later stage again will                for generating test cases is the Event Flow (basic flow and
        maximize the number of errors and make the process of                  alternate flow). The next step is creating the scenario based
        fixing errors become complex, and this phenomenon will                 on the Event Flow before it can be used to generate the test
        increase the budget of software development.                           cases.
                                                                                        However, automating the testing operation can
        * Noraida Binti Ismail; anoraida@yahoo.com                             reduce the cost and improve the reliability and effectiveness
                                                                               of software testing. Gutierez et al. (5) and Nebut et al. (2)
ISBN 978-979-16338-0-2                                                                                                                            699
Proceedings of the International Conference on                                                                                                   C-24
Electrical Engineering and Informatics
Institut Teknologi Bandung, Indonesia June 17-19, 2007
        have showed how testing operation can be automated. Nebut
        et al. (2) study an approach for automating the generation of
        system test scenarios from use cases in the context of object
        oriented embedded software and taking into account
        traceability problems between high-level views and concrete
        test case execution.
                 In this paper, we are going to use use-case diagrams
        to automatically generate test cases. These test cases will
        become a checked list for software engineers in order to
        validate the system’s requirement at the early software
        development stages.
        3. The System’s Requirements
                  In UML specification, requirements analysis and
        design are usually done using diagrams (1). One particular         Figure 1: A Use-Case Diagram for an online bookstore
        diagram (a use-case diagram) is used to specify requirements       system.
        of the system. In a use-case diagram, two important factors
        are used to describe the requirements of a system. They are                 Figure 1 shows a simple use-case diagram for a
        actors and use cases. Actors are external entities that interact   online bookstore system where only a registered user
        with the system and use cases are the behaviour (or the            (customer) is allowed to place an order for available items
        functionalities) of a system (9) The use cases are used to         on this web. These registered users are also able to cancel
        define the requirements of the system. These use cases             the order that they make at the previous session. On the other
        represent the functionalities of the system. Most often, each      hand, they may also check their order’s status.
        use case is then converted into a function representing the
        task of the system.                                                         Most often, use cases represent the functional
                                                                           requirements of a system. If the requirements are gathered
                 Therefore, we can convert from each of the use case       correctly, then a good use-case diagram can be formed. In
        into one test case or many test cases. The relationship of the     UML, sequence diagrams are usually used to manually
        conversion is either one to one or one to many. However, if        record the behaviour of a system by viewing the interaction
        we have many use cases, then we will have many test cases.         between the system and its environment (5). These sequence
        Therefore, an automatic tool would be more wisely used in          diagrams describe in details activities for use cases.
        order to generate test cases from use cases of any system.         Therefore, the sequence diagrams can be used to help in
                                                                           generating the correct test cases. Based on Figure 1, a use-
                  In most cases, use cases are developed based on the      case diagram can be used to generate test cases of that
        user perspective since the user is going to use the system. In     particular system. But before test cases can be generated, the
        order to make sure that the system does the requirements as        flow of events for each use cases must be defined first. As an
        it supposed to do, the test cases are designed according to the    example of one particular use case, Place an Order, the
        tester perspective. These test cases are basically designed to     expected flow of events and its exceptions are shown in
        test the input and output of a system. Most often, the input,      Table 1.
        key-in by the user, will be accepted by the system. The
        system then processes the input and produces the required                         Table 1:Place an Order Event Flow
        output according to its specification.                                                  Place an Order Event Flow
                  In this paper, we present an example of online                     1.    User enters web site address in the browser.
        bookstore system. The requirements of the system include
                                                                                     2.    User enters an email address and a password.
        the capability to make an order, cancel the order and check                             Exception 1: email address and a password is
        the status of his/her order. These three requirements are then                     not valid.
        transformed into a use-case diagram as shown in Figure 1.                               •     Log event
                                                                                                •     Use case ends
                                                                                     3.    User enters search string – partial name of a book.
                                                                                           Exception 2: No books matching search criteria
                                                                                           were found
                                                                                               •     Log event
                                                                                               •     Use case ends
                                                                                     4.    User selects a book.
                                                                                           Exception 3: Decline a book
                                                                                               •     Log event
                                                                                               •     Use case ends
ISBN 978-979-16338-0-2                                                                                                                           700
Proceedings of the International Conference on                                                                                                   C-24
Electrical Engineering and Informatics
Institut Teknologi Bandung, Indonesia June 17-19, 2007
                   5.    User adds the book to a shopping cart.                   Test Condition 5:
                                                                                  Continue shopping after storing a book in the shopping
                   6.    User selects "proceed to checkout" option.               cart
                         Exception 4: Continue shopping after storing a                •  An email address and a password.
                         book in the shopping cart                                     •  Matching search string were found
                             •     Log event                                           •  Selects the book.
                             •     Use case ends                                       •  Leave the book and select another book
                                                                                       •  Verify event is logged
                   7.    User confirms shipping address.
                         Exception 5: Enter a new address                         Test Condition 6:
                             •    Log event                                       Enter a new address
                             •    Use case ends                                        •   An email address and a password.
                                                                                       •   Matching search string were found
                   8.    User selects shipping option.                                 •   Selects a book and add the book to a shopping cart
                                                                                       •   Make a correction on the shipping address
                   9.    User confirms credit card that is stored in the               •   Change the shipping address.
                         system.
                                                                                       •   Verify event is logged
                         Exception 6: Enter a new credit card
                              •   Log event                                       Test Condition 7:
                              •   Use case ends                                   Enter a new credit card
                                                                                       •   An email address and a password.
                   10. User places the order.
                                                                                       •   Matching search string were found
                       Exception 7: Cancel order
                                                                                       •   Selects a book and add the book to a shopping cart
                           •    Log event
                                                                                       •   Confirms shipping address and shipping option.
                                     Use case ends
                                                                                       •   Enter invalid credit card number.
                                                                                       •   Change credit card number
                 From Table 1, sequence diagrams are formed to                         •   Verify event is logged
        record scenarios of the test cases. Based on Table 1 and test
        scenarios in sequence diagrams, we have derived the                       Test Condition 8:
        following test cases as shown in Table 2.                                 Cancel order
                                                                                       •   An email address and a password.
                        Table 2: Place an Order Test Case                              •   Matching search string was found.
                              Place an Order Test Case                                 •   Selects a book and add the book to a shopping cart.
                                                                                       •   Confirms shipping address and shipping option.
              Test Condition 1:                                                        •   Confirms credit card.
              Basic flow of event – valid account/data is entered.                     •   Click on cancel order button.
                   •    An email address and a password.                               •   Sign out of the account without place an order.
                   •    Matching search string were found                              •   Verify event is logged.
                   •    Selects a book and add the book to a shopping cart
                   •    Confirms shipping address and shipping option.
                   •    Confirms credit card                                 4. The tool
                   •    Places the order                                              The tool, which we call GenTCase (Generator for
                                                                             Test Cases), can be used to layout the use-case diagram of
              Test Condition 2:
                                                                             any system. The tool is also able to automatically generate
              Email address and a password is invalid.
                   •  Enter wrong combination of an email address and a
                                                                             the test cases of the system according to the use-case
                      password                                               diagram that has been formed previously. The tool is
                   •  Enter unavailable of email address or password.        developed using object-oriented approach with C++
                   •  Verify event is logged                                 programming language. The tool has 3 major components as
                                                                             shown in Figure 2.
              Test Condition 3:
              No books matching search criteria were found
                   •  An email address and a password.
                   •  Enter search string which is not spelled correctly.           Workspace      Î     Engine    Î         Test
                   •  Verify event is logged.
                                                                                                                            Cases
              Test Condition 4:
              Decline a book
                   •   An email address and a password.                                    Figure 2: Components of GenTCase
                   •   Matching search string was found.
                   •   Enter a new search string.                                     From Figure 2, the tool allows a user to layout the
                   •   Verify event is logged                                use-case diagram of any system in the workspace provided.
                                                                             The workspace is used as a place for a user to provide the
                                                                             system’s requirements by means of a use-case diagram. In
ISBN 978-979-16338-0-2                                                                                                                           701
Proceedings of the International Conference on                                                                                                        C-24
Electrical Engineering and Informatics
Institut Teknologi Bandung, Indonesia June 17-19, 2007
        the workspace, a ToolBox is used to create, edit and display       generator of test cases (GTC) in the Workspace can be used
        the use-case diagram. The ToolBox consists of standard             to generate the test cases.
        symbols and arrows for a use-case diagram such as symbols
        for an actor and a use case, and arrows for connecting an          5. Conclusion and Future Work
        actor with use cases as well as arrow for generalizations. In                GenTCase is a tool that is able to generate the test
        the Workspace, a user can also type-in the text for each of        cases automatically according to the system’s requirements.
        the use cases used in the Text Box provided by the tool. The       The test cases can be used as a checklist for a programmer to
        Workspace will allow a user of the tool to layout the use-         validate that the system meets its requirements. The purpose
        case diagram according to any system.                              of GenTCase is to reduce the cost of testing the system.
                                                                           However, GenTCase has its limitations where the use cases
                 Once the use-case diagram has been finalized, the         used are only for functional requirements of a system. The
        user can generate the test cases by using the generator of the     tool is unable to capture the non-functional requirements of a
        tool. The Engine will take all the use cases and search the        system. Therefore, the non-functional requirements need to
        keywords used in the provided database. The database               be captured and tested outside of the tool.
        consists of most standard keywords of a use case. Once the
        use case used matches the keyword inside the database, the
        engine will generate its respective test cases according to its    6. Acknowledgements
        use case. Intelligent search technique is used to search all the           This research is under UTHM Fundamental
        metadata fields in the entire database.                            Research Grant Vot 0233.
                 The intelligent searching technique includes three        7. References
        major processes. First, the keywords are pre-processed by
        some automatic text operation methods. The result is a             (1)   A. Bahrami Object oriented systems development : using the unified
        collection of metadata, which is considered the logical view             modeling language, Mc-Graw Hill, Singapore. (1999)
        of the use case diagram. Next, the metadata describing the
                                                                           (2)   C. Nebut, F. Fleurey and Y.L. Traon, Automatic Test Geneartion: A
        logical views are used to construct a metadata-oriented                  Use Case Driven Approach, IEEE TRANSACTION ON SOFTWARE
        index. An index such as this “allows fast searching over                 ENGINEERING Vol.32, No.3 (2003)
        large volumes of metadata field”.
                                                                           (3)   D. Wood and J. Reis (1999). Use Case Derived Test Cases, Software
                                                                                 Quality Engineering for Software Testing Analysis and Review
                 During the retrieval, the information retrieval                 (STAREAST99) Online. http://www.stickyminds.com/
        engine first performs similar text operations on the user
        query as those performed on the original use cases. The            (4)   I. Jacobson, G. Booch, J. Rumbaugh. The Unified Software
        output of the text operation is a list of metadata, each of              Development, England (1992)
        which is used to locate, through the index, a list of all the      (5)   J. Gutierez, Escalona M.J. and Torres M.M. An Approach to Generate
        documents in which it occurs. When multiple metadata are                 Test Cases from Use Cases, Proceedings of the 6th International
        present in the query, the search returns the union of the                Conference on Web Engineering. pp. 113-114 (2006).
        additional information retrieved by all the words. In short,
                                                                           (6)   J. Heumann, Generating Test Cases from Use Cases, Rational
        searching is a process of matching keywords in the use cases             Software, IBM. (2001).
        with those in the query. Lastly, every retrieved metadata is
        evaluated by its relevance to the query and the additional         (7)   J. Jansen Using an Intelligent Agent To Enhance Search Engine
        information of use cases. The way the engine works is by                 Performance http://www.firstmonday.org (1996)
        choosing the shortest time-to-locate the object being              (8)   R.V. Binder Testing Object-Oriented System. Addison-Wesley. USA
        searched. This will ensure the result returns in few seconds.            (2000)
                 The tool will produce the test cases based on the         (9)   Rational. (2003). Mastering Requirements Management with Use
                                                                                 Cases, Rational Software, IBM.
        use-case diagram provided in the workspace. These test
        cases are generated automatically from the tool as the output      (10) T. Stanley, Intelligent Searching Agent on the Web,
        of the tool. The output is displayed on the screen as well as           http://ariadne.ac.uk/issue7/search-engine
        stored in a file with extension .txt, namely output.txt. A user
        can open this output file by using a NotePad or Microsoft
        Word. The output can be used as a checklist for a
        programmer to test the system that he or she will develop
        according to the provided test cases. These test cases can
        also be used to validate the results of the test cases so the
        requirements of the system are meet.
                 User who uses the tool can layout the use cases
        using the Workspace. The Tool Box is used in order to ease
        the drawing of the use-case diagram. Then, the button for
ISBN 978-979-16338-0-2                                                                                                                                702