Pseudo-classes: very simple and lightweight mockObject-like classes for unit-testing

  • Authors:
  • Geoff Sobering;Levi Cook;Steve Anderson

  • Affiliations:
  • Isthmus Group, Madison, WI;Isthmus Group, Madison, WI;Berbee, Madison, WI

  • Venue:
  • OOPSLA '04 Companion to the 19th annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

A simple alternative to MockObjects is presented. Given the interface of an object required by a class-under-test, a Pseudo-Class is created implementing all methods such that they immediately fail. A test-specific sub-class of the Pseudo-Class is created locally in the test (ex. as an anonymous inner-class in Java), over-riding only the methods required by the interaction between the object and the class-under-test for the test-scenario. Typically, the method implementations are extremely simple (a few lines, at most), and the number of methods overridden is small. This mechanism was found adequate for more than 90% of our unit-tests (in a 1000-class system with over 2000 test methods, we finally ended up with about four real MockObject classes and more than 40 Pseudo-Classes).