Automating Java Program Testing Using OCL and AspectJ

Random testing can eliminate subjectiveness in constructing test data and increase the diversity of test data. However, one difficult problem is to construct test oracles that decide test results---test failures or successes. Assertions can be used as test oracles and are most effective when they are derived from formal specifications such as OCL constraints. Random testing, if fully automated, can reduce the cost of testing dramatically. We propose an automated testing approach for Java programs by combining random testing and OCL. The key idea of our approach is to use OCL constraints as test oracles by translating them to runtime checks written in AspectJ. We implement our approach by adapting existing frameworks for translating OCL to AspectJ and assertion-based random testing. We evaluate the effectiveness of our approach through case studies and experiments. The results are encouraging in that our approach can detect errors in both implementations and OCL constraints and provide a practical means for using OCL.

[1]  David Lorge Parnas,et al.  Using Test Oracles Generated from Program Documentation , 1998, IEEE Trans. Software Eng..

[2]  Anneke Kleppe,et al.  The Object Constraint Language: Getting Your Models Ready for MDA , 2003 .

[3]  William G. Griswold,et al.  An Overview of AspectJ , 2001, ECOOP.

[4]  Steve Roach,et al.  An Aspect-Based Approach to Checking Design Constraints at Run-Time , 2009, 2009 Sixth International Conference on Information Technology: New Generations.

[5]  Lorenz Froihofer,et al.  Overview and Evaluation of Constraint Validation Approaches in Java , 2007, 29th International Conference on Software Engineering (ICSE'07).

[6]  B. Demuth,et al.  Model and Object Verification by Using Dresden OCL , 2009 .

[7]  Gary T. Leavens,et al.  A Simple and Practical Approach to Unit Testing: The JML and JUnit Way , 2002, ECOOP.

[8]  Carlos E. Rubio-Medrano,et al.  Random Test Data Generation for Java Classes Annotated with JML Specifications , 2007, Software Engineering Research and Practice.

[9]  David Coppit,et al.  On the Use of Specification-Based Assertions as Test Oracles , 2005, 29th Annual IEEE/NASA Software Engineering Workshop.

[10]  Martin Gogolla,et al.  Aspect-Oriented Monitoring of UML and OCL Constraints , 2007 .

[11]  Lionel C. Briand,et al.  Instrumenting contracts with aspect-oriented programming to increase observability and support debugging , 2005, 21st IEEE International Conference on Software Maintenance (ICSM'05).

[12]  Richard G. Hamlet,et al.  Data Abstraction, Implementation, Specification, and Testing , 1981, TOPL.

[13]  Yannis Smaragdakis,et al.  JCrasher: an automatic robustness tester for Java , 2004, Softw. Pract. Exp..

[14]  Steve Roach,et al.  Checking Design Constraints at Run-time Using OCL and AspectJ , 2009 .