The JML and JUnit Way of Unit Testing and its Implementation

Writing unit test code is labor-intensive, hence it is often not done as an integral part of programming. However, unit testing is a practical approach to increasing the correctness and quality of software; for example, Extreme Programming relies on frequent unit testing. In this paper we present a new approach that makes writing unit tests easier. It uses a formal specification language’s runtime assertion checker to decide whether methods are working correctly; thus code to decide whether tests pass or fail is automatically produced from specifications. Our tool combines this testing code with hand-written test data to execute tests. Therefore, instead of writing testing code, the programmer writes formal specifications (e.g., preand postconditions). This makes the programmer’s task easier, because specifications are more concise and abstract than the equivalent test code, and hence more readable and maintainable. Furthermore, by using specifications in testing, specification errors are quickly discovered, so the specifications are more likely to provide useful documentation and inputs to other tools. In this paper we describe an implementation using the Java Modeling Language (JML) and the JUnit testing framework, but the approach could be easily implemented with other combinations of formal specification languages and unit testing tools.

[1]  Yoonsik Cheon,et al.  A Runtime Assertion Checker for the Java Modeling Language (JML) , 2003, ICSE 2003.

[2]  Nancy G. Leveson,et al.  An experimental evaluation of the assumption of independence in multiversion programming , 1986, IEEE Transactions on Software Engineering.

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

[4]  James L. Crowley,et al.  Issues in the full scale use of formal methods for automated testing , 1996, ISSTA '96.

[5]  Reinhold Plösch,et al.  Contracts: from analysis to C++ implementation , 1999, Proceedings of Technology of Object-Oriented Languages and Systems - TOOLS 30 (Cat. No.PR00278).

[6]  B. Eng,et al.  GENERATING A TEST ORACLE FROM PROGRAM DOCUMENTATION , 1995 .

[7]  Richard G. Hamlet,et al.  Testing Programs with the Aid of a Compiler , 1977, IEEE Transactions on Software Engineering.

[8]  Wolfram Schulte,et al.  Runtime verification of .NET contracts , 2003, J. Syst. Softw..

[9]  Stephen H. Edwards,et al.  Part II: specifying components in RESOLVE , 1994, SOEN.

[10]  Kent Beck,et al.  Test-infected: programmers love writing tests , 2000 .

[11]  Software and Component Testing: Using Jtest ® to Automate Unit Testing and Coding Standard Enforcement , .

[12]  David S. Rosenblum A Practical Approach to Programming With Assertions , 1995, IEEE Trans. Software Eng..

[13]  Andrew Duncan,et al.  Adding Contracts to Java with Handshake , 1998 .

[14]  K. Beck,et al.  Extreme Programming Explained , 2002 .

[15]  Stephen H. Edwards,et al.  Model variables: cleanly supporting abstraction in design by contract , 2005, Softw. Pract. Exp..

[16]  Debra J. Richardson,et al.  TAOS: Testing with Analysis and Oracle Support , 1994, ISSTA '94.

[17]  Wolfram Schulte,et al.  The ABCs of specification: asml, behavior, and components , 2001, Informatica.

[18]  Bart Jacobs,et al.  A Logic for the Java Modeling Language JML , 2001, FASE.

[19]  Stephen H. Edwards,et al.  A framework for detecting interface violations in component-based software , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[20]  Abhay Bhorkar,et al.  A Run-time Assertion Checker for Java using JML , 2000 .

[21]  Albert L. Baker,et al.  Enhancing the Pre- and Postcondition Technique for More Expressive Specifications , 1999, World Congress on Formal Methods.

[22]  Bogdan Korel,et al.  Automated regression test generation , 1998, ISSTA '98.

[23]  Pedro Guerreiro Simple support for design by contract in C++ , 2001, Proceedings 39th International Conference and Exhibition on Technology of Object-Oriented Languages and Systems. TOOLS 39.

[24]  David J. Panzl Automatic Software Test Drivers , 1978, Computer.

[25]  David Welch,et al.  An Exception-Based Assertion Mechanism for C++ , 1998, Journal of object-oriented programming.

[26]  Michael D. Ernst,et al.  An overview of JML tools and applications , 2003, Electron. Notes Theor. Comput. Sci..

[27]  K. Rustan M. Leino,et al.  Extended static checking , 1998, PROCOMET.

[28]  Richard G. Hamlet,et al.  Automatically Checking an Implementation against Its Formal Specification , 2000, IEEE Trans. Software Eng..

[29]  Ernesto Pimentel,et al.  Design by Contract in Smalltalk , 1996, J. Object Oriented Program..

[30]  Sriram Sankar,et al.  Structural specification-based testing with ADL , 1996, ISSTA '96.

[31]  Marie-Claude Gaudel,et al.  Software testing based on formal specifications: a theory and a tool , 1991, Softw. Eng. J..

[32]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[33]  Albert L. Baker,et al.  JML: A Notation for Detailed Design , 1999, Behavioral Specifications of Businesses and Systems.

[34]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[35]  Bertrand Meyer,et al.  Applying 'design by contract' , 1992, Computer.

[36]  Heike Wehrheim,et al.  Jass - Java with Assertions , 2001, RV@CAV.

[37]  Stuart H. Zweben,et al.  Part I: the RESOLVE framework and discipline: a research synopsis , 1994, SOEN.

[38]  Albert L. Baker,et al.  Preliminary design of JML: a behavioral interface specification language for java , 2006, SOEN.

[39]  John L. Bruno,et al.  jContractor: A Reflective Java Library to Support Design by Contract , 1999, Reflection.

[40]  R. Kramer iContract - The Java(tm) Design by Contract(tm) Tool , 1998 .

[41]  Karine Arnout,et al.  The .NET Contract Wizard: adding Design by Contract to languages other than Eiffel , 2001, Proceedings 39th International Conference and Exhibition on Technology of Object-Oriented Languages and Systems. TOOLS 39.

[42]  Teruo Higashino,et al.  Automatic Analysis and Test Case Derivation for a Restricted Class of LOTOS Expressions with Data Parameters , 1994, IEEE Trans. Software Eng..

[43]  Pankaj Jalote Specification and Testing of Abstract Data Types , 1992, Comput. Lang..

[44]  Matthias Felleisen,et al.  Behavioral Interface Contracts for Java , 2000 .

[45]  David A. Carrington,et al.  Test templates: a specification-based testing framework , 1993, Proceedings of 1993 15th International Conference on Software Engineering.

[46]  Steven P. Reiss,et al.  CCEL: A Metalanguage for C++ , 1992, C++ Conference.

[47]  Sara Porat,et al.  Class Assertions in C++ , 1995, J. Object Oriented Program..

[48]  Sriram Sankar,et al.  ADL—an interface definition language for specifying and testing software , 1994 .