|
This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
|
Original Post: Unit testing a singleton
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Darrell Norton
Latest Posts From Darrell Norton's Blog
|
|
Jonathan de Halleux shows the simple way to test a singleton. Given this sample code: using System; public sealed class Singleton { ... private Singleton() {} public static Singleton Instance { get { ...} } }
You can test it with reflection like this: using System.Reflection; [TestFixture] public class SingletonTest { private Singleton target = null; [SetUp] public void SetUp() { ConstructorInfo ci = typeof(Singleton).GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic, null, Type.EmptyTypes, null ); Assert.IsNotNull(ci); this.target = (Singleton)ci.Invoke(null); } } This Blog Hosted On: http://www.DotNetJunkies.com/
Read: Unit testing a singleton
|