Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.5555/646159.680018guideproceedingsArticle/Chapter ViewAbstractPublication PagesConference Proceedingsacm-pubtype
Article

A Simple and Practical Approach to Unit Testing: The JML and JUnit Way

Published: 10 June 2002 Publication History

Abstract

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, the Extreme Programming approach 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 automating the writing of unit test oracles. These oracles can be easily combined with hand-written test data. Instead of writing testing code, the programmer writes formal specifications (e.g., pre- and 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. We have implemented this idea 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 test tools.

References

[1]
Karine Arnout and Raphael Simon. The .NET contract wizard: Adding design by contract to languages other than Eiffel. In Proceedings of TOOLS 39, 29 July -3 August 2001, Santa Barbara, California , pages 14-23. IEEE Computer Society, 2001.
[2]
D. Bartetzko, C. Fischer, M. Moller, and H. Wehrheim. Jass - Java with assertions. In Workshop on Runtime Verification held in conjunction with the 13th Conference on Computer Aided Verification, CAV'01 , 2001.
[3]
Kent Beck and Erich Gamma. Test infected: Programmers love writing tests. Java Report , 3(7), July 1998.
[4]
Kent Beck. Extreme Programming Explained . Addison-Wesley, 2000.
[5]
Gilles Bernot, Marie Claude Claudel, and Bruno Marre. Software testing based on formal specifications: a theory and a tool. Software Engineering Journal , 6(6):387- 405, November 1991.
[6]
Abhay Bhorkar. A run-time assertion checker for Java using JML. Technical Report TR #00-08, Department of Computer Science; Iowa State University, Ames, IA, May 2000.
[7]
Manuela Carrillo-Castellon, Jesus Garcia-Molina, Ernesto Pimentel, and Israel Repiso. Design by contract in Smalltalk. Journal of Object-Oriented Programming , 9(7):23-28, November/December 1996.
[8]
Juei Chang, Debra J. Richardson, and Sriram Sankar. Structural specification-based testing with ADL. In Proceedings of ISSTA 96, San Diego, CA , pages 62-70. IEEE Computer Society, 1996.
[9]
Yoonsik Cheon and Gary T. Leavens. A runtime assertion checker for the Java Modeling Language (JML). Technical Report 02-05, Department of Computer Science, Iowa State University, March 2002.
[10]
J. L. Crowley, J. F. Leathrum, and K. A. Liburdy. Isues in the full scale use of formal methods for automated testing. ACM SIGSOFT Software Engineering Notes , 21(3):71-78, May 1996.
[11]
David L. Detlefs, K. Rustan M. Leino, Greg Nelson, and James B. Saxe. Extended static checking. SRC Research Report 159, Compaq Systems Research Center, 130 Lytton Ave., Palo Alto, Dec 1998.
[12]
Carolyn K. Duby, Scott Meyers, and Steven P. Reiss. CCEL: A metalanguage for C++. In USENIX C++ Technical Conference Proceedings , pages 99-115, Portland, OR, August 1992. USENIX Assoc. Berkeley, CA, USA.
[13]
Andrew Duncan and Urs Holzle. Adding contracts to Java with Handshake. Technical Report TRCS98-32, Department of Computer Science, University of California, Santa Barbara, CA, December 1998.
[14]
Robert Bruce Findler and Matthias Felleisen. Behavioral interface contracts for Java. Technical Report CS TR00-366, Department of Computer Science, Rice University, Houston, TX, August 2000.
[15]
Pedro Guerreiro. Simple support for design by contract in C++. In Proceedings of TOOLS 39, 29 July -3 August 2001, Santa Barbara, California , pages 24-34. IEEE Computer Society, 2001.
[16]
R. G. Hamlet. Testing programs with the aid of a compiler. IEEE Transactions on Software Engineering , 3(4):279-290, July 1977.
[17]
Teruo Higashino and Gregor v. Bochmann. Automatic analysis and test case derivation for a restricted class of LOTOS expressions with data parameters. IEEE Transactions on Software Engineering , 20(1):29-42, January 1994.
[18]
Bart Jacobs and Eric Poll. A logic for the Java modeling language JML. In Fundamental Approaches to Software Engineering (FASE'2001), Genova, Italy, 2001 , volume 2029 of Lecture Notes in Computer Science , pages 284-299. Springer-Verlag, 2001.
[19]
Pankaj Jalote. Specification and testing of abstract data types. Computing Languages , 17(1):75-82, 1992.
[20]
JUnit. Http://www.junit.org.
[21]
Murat Karaorman, Urs Holzle, and John Bruno. jContractor: A reflective Java library to support design by contract. In Pierre Cointe, editor, Meta-Level Architectures and Reflection, Second International Conference on Reflection '99, Saint-Malo, France, July 19-21, 1999, Proceedings , volume 1616 of Lecture Notes in Computer Science , pages 175-196. Springer-Verlag, July 1999.
[22]
Bogdan Korel and Ali M. Al-Yami. Automated regression test generation. In Proceedings of ISSTA 98, Clearwater Beach, FL , pages 143-152. IEEE Computer Society, 1998.
[23]
Reto Kramer. iContract - the Java design by contract tool. TOOLS 26: Technology of Object-Oriented Kanguages and Systems, Los Alamitos, California , pages 295- 307, 1998.
[24]
Gary T. Leavens, Albert L. Baker, and Clyde Ruby. Preliminary design of JML: A behavioral interface specification language for Java. Technical Report 98- 06p, Iowa State University, Department of Computer Science, August 2001. See www.jmlspecs.org.
[25]
Gary T. Leavens, Albert L. Baker, and Clye Ruby. JML: A notation for detailed design. In Haim Kilov, Bernhard Rumpe, and Ian Simmonds, editors, Behavioral Specifications of Businesses and Systems , chapter 12, pages 175-188. Kluwer, 1999.
[26]
Gary T. Leavens and Albert L. Baker. Enhancing the pre- and postcondition technique for more expressive specifications. In J. Davies J.M. Wing, J. Woodcock, editor, FM'99 - Formal Methods, World Congress on Formal Methods in the Development of Computing Systems, Toulouse, France, September 1999. Proceedings, Volume II , volume 1708 of Lecture Notes in Computer Science , pages 1087-1106. Springer-Verlag, September 1999.
[27]
Bertrand Meyer. Eiffel: The Language . Object-Oriented Series. Prentice Hall, New York, N.Y., 1992.
[28]
Bertrand Meyer. Object-oriented Software Construction . Prentice Hall, New York, N.Y., second edition, 1997.
[29]
B. Meyer. Applying design by contract. IEEE Computer , 25(10):40-51, October 1992.
[30]
D.J. Panzl. Automatic software test driver. IEEE Computer , pages 44-50, April 1978.
[31]
Dennis Peters and David L. Parnas. Generating a test oracle from program documentation. In Proceedings of ISSTA 94, Seattle, Washington, August, 1994 , pages 58-65. IEEE Computer Society, August 1994.
[32]
Reinhold Plosch and Josef Pichler. Contracts: From analysis to C++ implementation. In Proceedings of TOOLS 30 , pages 248-257. IEEE Computer Society, 1999.
[33]
Sara Porat and Paul Fertig. Class assertions in C++. Journal of Object-Oriented Programming , 8(2):30-37, May 1995.
[34]
Debra J. Richardson. TAOS: Testing with analysis and oracle support. In Proceedings of ISSTA 94, Seattle, Washington, August, 1994 , pages 138-152. IEEE Computer Society, August 1994.
[35]
David R. Rosenblum. A practical approach to programming with assertions. IEEE Transactions on Software Engineering , 21(1):19-31, January 1995.
[36]
Sriram Sankar and Roger Hayes. ADL: An interface definition language for specifying and testing software. ACM SIGPLAN Notices , 29(8):13-21, August 1994. Proceedings of the Workshop on Interface Definition Language, Jeannette M. Wing (editor), Portland, Oregon.
[37]
P. Stocks and D. Carrington. Test template framework: A specification-based test case study. In Proceedings of the 1993 International Symposium on Software Testing and Analysis (ISSTA) , pages 11-18. IEEE Computer Society, June 1993.
[38]
David Welch and Scott Strong. An exception-based assertion mechanism for C++. Journal of Object-Oriented Programming , 11(4):50-60, July/August 1998.

Cited By

View all
  • (2023)JMLKelinci+: Detecting Semantic Bugs and Covering Branches with Valid Inputs Using Coverage-guided Fuzzing and Runtime Assertion CheckingFormal Aspects of Computing10.1145/360753836:1(1-24)Online publication date: 5-Aug-2023
  • (2019)Java reflection API: revealing the dark side of the mirrorProceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3338906.3338946(636-646)Online publication date: 12-Aug-2019
  • (2018)Translating code comments to procedure specificationsProceedings of the 27th ACM SIGSOFT International Symposium on Software Testing and Analysis10.1145/3213846.3213872(242-253)Online publication date: 12-Jul-2018
  • Show More Cited By

Index Terms

  1. A Simple and Practical Approach to Unit Testing: The JML and JUnit Way
    Index terms have been assigned to the content through auto-classification.

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Guide Proceedings
    ECOOP '02: Proceedings of the 16th European Conference on Object-Oriented Programming
    June 2002
    635 pages
    ISBN:3540437592

    Publisher

    Springer-Verlag

    Berlin, Heidelberg

    Publication History

    Published: 10 June 2002

    Qualifiers

    • Article

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)0
    • Downloads (Last 6 weeks)0
    Reflects downloads up to 30 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2023)JMLKelinci+: Detecting Semantic Bugs and Covering Branches with Valid Inputs Using Coverage-guided Fuzzing and Runtime Assertion CheckingFormal Aspects of Computing10.1145/360753836:1(1-24)Online publication date: 5-Aug-2023
    • (2019)Java reflection API: revealing the dark side of the mirrorProceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3338906.3338946(636-646)Online publication date: 12-Aug-2019
    • (2018)Translating code comments to procedure specificationsProceedings of the 27th ACM SIGSOFT International Symposium on Software Testing and Analysis10.1145/3213846.3213872(242-253)Online publication date: 12-Jul-2018
    • (2018)Specification-Based Testing in Software Engineering CoursesProceedings of the 49th ACM Technical Symposium on Computer Science Education10.1145/3159450.3159575(800-805)Online publication date: 21-Feb-2018
    • (2018)Contract-based testing for PHP with PraspelJournal of Systems and Software10.1016/j.jss.2017.06.017136:C(209-222)Online publication date: 1-Feb-2018
    • (2016)Automatic generation of oracles for exceptional behaviorsProceedings of the 25th International Symposium on Software Testing and Analysis10.1145/2931037.2931061(213-224)Online publication date: 18-Jul-2016
    • (2016)Making Formal Methods More Relevant to Software Engineering Students via Automated Test GenerationProceedings of the 2016 ACM Conference on Innovation and Technology in Computer Science Education10.1145/2899415.2899424(224-229)Online publication date: 11-Jul-2016
    • (2015)Combining dynamic analysis and visualization to explore the distribution of unit test suitesProceedings of the Sixth International Workshop on Emerging Trends in Software Metrics10.5555/2821491.2821497(21-30)Online publication date: 16-May-2015
    • (2015)Calculation coverage testing in scientific applicationsProceedings of the 2015 International Symposium on Software Testing and Analysis10.1145/2771783.2771807(350-360)Online publication date: 13-Jul-2015
    • (2015)The Oracle Problem in Software Testing: A SurveyIEEE Transactions on Software Engineering10.1109/TSE.2014.237278541:5(507-525)Online publication date: 1-May-2015
    • Show More Cited By

    View Options

    View options

    Get Access

    Login options

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media