1 A Model-Based Approach to Test Generation for Aspect-Oriented Programs Weifeng Xu Department of Computer Science North Dakota State University Fargo, ND 58105, U.S.A weifeng.xu@ndsu.edu Dianxiang Xu Department of Computer Science North Dakota State University Fargo, ND 58105, U.S.A dianxiang.xu@ndsu.edu ABSTRACT This paper presents an approach to generating tests for adequately exercising interaction between aspects and classes based on aspect-oriented UML models. In this approach, an aspect-oriented model consists of class diagrams, aspect diagrams, and sequence diagrams. Since methods of classes and advices of aspects are both specified by sequence diagrams, the advices on a given method can be weaved into a new sequence diagram, which is essential to the weaving mechanism in AOSD. For a woven sequence diagram, the approach exploits goal-directed reasoning to construct a flow graph for a given coverage criteria (e.g. the combination of branch coverage and polymorphic coverage in this paper), and further expands the graph to a flow tree, where each path is a test. Then the approach derives objects with desired states for exercising each test in the flow tree. Categories and Subject Descriptors D.2.5 [Software Engineering]: Testing and Debugging - Testing tools (e.g., data generators, coverage testing) General Terms Algorithms, Design, Languages Keywords Aspect-oriented programming, testing, UML, sequence diagram, test generation. 1. INTRODUCTION An aspect-oriented program typically consists of a number of modules (or classes) and aspects that can be woven into an executable whole [1][2][3]. The crosscutting mechanism of aspects frees the programmer from interweaving different concerns (i.e. goals, concepts, or areas of interests) in a monotonous program hierarchy imposed by the base language. This greatly facilitates identifying and modularizing separate concerns that crosscut multiple functional components or objects. The dynamic behavior of objects, including interactions, dependencies, and constraints on the message sequences, is therefore determined collectively by the specification of both objects (classes) and aspects. The interaction between aspects and classes may introduce a variety of bug hazards into the system [4]. To name a few, improper join points, pointcuts, and advices likely lead to unexpected system behaviors or even failures. In Aspect- Oriented Software Development (AOSD), validating whether or not the aspects of crosscutting concerns are implemented correctly is a major issue. To test an aspect-oriented system implementation, it is desirable to adequately exercise classes as well as aspects. This paper presents an approach to generating tests for adequately exercising interaction between aspects and classes based on aspect-oriented UML models. In this approach, an aspect-oriented model consists of class diagrams, aspect diagrams, and sequence diagrams. Since methods of classes and advices of aspects are both specified by sequence diagrams, the advices on a given method can be weaved into a new sequence diagram, which is essential to the weaving mechanism in AOSD. Based on a woven sequence diagram, the approach exploits goal-directed reasoning to construct a flow graph for a given coverage criteria (e.g. the combination of branch coverage and polymorphic coverage in this paper), and further expands the graph to a flow tree, where each path is a test. Then the approach derives objects with desired states for exercising each test in the flow tree. The rest of the paper is organized as follows. Section 2 briefly reviews related work on testing aspect-oriented programs. In section 3, we introduce UML-based aspect-oriented modeling. In section 4, we present how to generate test cases. Section 5 concludes the paper. 2. RELATED WORK AOSD as an emerging paradigm of software development is still in its infancy. It is not surprising to see that little research on testing aspect-oriented programs has been published [4]. Zhao has proposed a data flow based approach to unit testing of aspect-oriented programs [10]. For each aspect or class, the approach performs three levels of testing, i.e., intra-module, inter- module, and intra-aspect/intra-class testing. Definition-Use pairs (DU-pairs) are constructed to determine what interactions between aspects and classes must be tested. Zhao and Rinard [11] have also exploited system dependence graphs to capture the additional structures in aspect-oriented features such as join points, advice, aspects, and interactions between aspects and classes. In this approach, control flow graphs are constructed at both system and module level, and test suites are derived from control flow graphs. No fault model is targeted to help detect most likely faults. Alexander, Bieman, and Andrews [4] have recently proposed a fault model for aspect-oriented programming, which includes six types of faults: incorrect strength in pointcut patterns, incorrect Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Submission to AOSD’05 Workshop on Testing AOP. Copyright XXXX XXX X-XXXXX-XXX-X/XX/XXXX…$X.00.