Evil Singleton Mocking with Natural™ Mocks

Ok, so we all know that Singletons are Evil, and Hard to test but sometimes you just have to be bad.

We have added some more support for Singletons in the coming TypeMock version.
With Naturalâ„¢ Mocks, it is quite easy to mock a Singleton. Here is how: 

public class MyServer { public string Host { get { return Singleton.Instance.GetHost(); } } } [Test] public void TestSingleton() { string expectedHost = "wow"; using (RecordExpectations record = new RecordExpectations()) { Singleton.Instance.GetHost(); record.Return(expectedHost); } MyServer server = new MyServer(); Assert.AreEqual(expectedHost, server.Host); MockManager.Verify(); }

Couldn’t be simpler:
TypeMock will know that Singleton is a singleton, and will do all the mocking for you.

Bookmark at:
Add 'Evil Singleton Mocking with Natural™ Mocks' to Del.icio.us Add 'Evil Singleton Mocking with Natural™ Mocks' to digg Add 'Evil Singleton Mocking with Natural™ Mocks' to reddit Add 'Evil Singleton Mocking with Natural™ Mocks' to Feed Me Links! Add 'Evil Singleton Mocking with Natural™ Mocks' to Technorati Add 'Evil Singleton Mocking with Natural™ Mocks' to Yahoo My Web Add 'Evil Singleton Mocking with Natural™ Mocks' to Newsvine Add 'Evil Singleton Mocking with Natural™ Mocks' to FURL Add 'Evil Singleton Mocking with Natural™ Mocks' to blinklist Add 'Evil Singleton Mocking with Natural™ Mocks' to My-Tuts 

19 February 2007 | .NET Tests | Comments | Print This Post

Leave a Reply

  1.  
  2.  
  3.  
Search Eli Lopian’s Blog (TypeMock)

Navigation

Recent Posts

Categories

Archives

Managment