Automatically extracting mock object behavior from Design by Contract™ specification for test data generation

  • Authors:
  • Stefan J. Galler;Andreas Maller;Franz Wotawa

  • Affiliations:
  • Graz University of Technology, Inffeldgasse, Graz, Austria;Graz University of Technology, Inffeldgasse, Graz, Austria;Graz University of Technology, Inffeldgasse, Graz, Austria

  • Venue:
  • Proceedings of the 5th Workshop on Automation of Software Test
  • Year:
  • 2010

Quantified Score

Hi-index 0.00

Visualization

Abstract

Test data generation is an important task in the process of automated unit test generation. Random and heuristic approaches are well known for test input data generation. Unfortunately, in the presence of complex pre-conditions especially in the case of non-primitive data types those approaches often fail. A promising technique for generating an object that exactly satisfies a given pre-condition is mocking, i.e., replacing the concrete implementation with an implementation only considering the necessary behavior for a specific test case. In this paper we follow this technique and present an approach for automatically deriving the behavior of mock objects from given Design by Contract™ specifications. The generated mock objects behave according to the Design by Contract™ specification of the original class. Furthermore, we make sure that the observed behavior of the mock object satisfies the pre-condition of the method under test. We evaluate the approach using the Java implementations of 20 common Design Patterns and a stack based calculator. Our approach clearly outperforms pure random data generation in terms of line coverage.