Template method test pattern

A. Bijlsma, H.J.M. Passier, H.J. Pootjes, S. Stuurman

Research output: Contribution to journalArticleAcademicpeer-review

Abstract

How to test abstract classes is an area of testing that is not paid much attention
to. Abstract classes cannot be instantiated and therefore standard execution-
based test strategies are not applicable.
In this paper, we consider a special case of an abstract class, namely one
produced by the Template Method pattern. This pattern results in an abstract
class, with a concrete template method and one or more abstract primitive
operations, and one or more subclasses, implementing the primitive operations
specifically for each subclass.
How should we test an instance of the Template Method pattern? Testing
the concrete template method by testing the abstract class is impossible. Testing
an instance of the Template Method pattern by testing the template method in
all of the subclasses individually is error-prone in the long run.
This paper presents a structured approach to test instances of the Template
Method pattern in an elegant way using the Abstract Factory pattern. Fur-
thermore, we introduce the new concept
semi-abstract method
to reason about
concrete methods that depend on abstract operations. We formalize the pattern
and demonstrate the approach at work using an example program.
Original languageEnglish
Pages (from-to)8-12
Number of pages5
JournalInformation Processing Letters
Volume139
Issue number2018
DOIs
Publication statusPublished - Nov 2018

    Fingerprint

Keywords

  • Software testing
  • Software design and implementation
  • Abstract classes
  • Template Method

Cite this