TheSilverBullet
TheSilverBullet

Reputation: 625

Unit testing in case of a service locator pattern

I am using moles framework to unit test my code.

There is an implementation of a singleton class with

  1. A private (empty) constructor
  2. A public static readonly Instance variable

This class implements an abstract class.

How do I circumvent the Initialization function of my singleton class? This Initialization function is called from the constructor of the abstract base class.

Upvotes: 2

Views: 613

Answers (1)

Stealth Rabbi
Stealth Rabbi

Reputation: 10346

You can subclass your singleton to make a "for testing" version. You can make your initilization function abstract, and have your real singleton implement what you're currently doing, and have the testing version implement something to initialize your test version.

Upvotes: 1

Related Questions