简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM