Reputation: 1857
How to write test in Nunit to test that only one instance is created by my singleton class.
Upvotes: 1
Views: 403
Reputation: 30819
Create the object twice and use Assert to make sure they have the same reference
Upvotes: 1
Reputation: 56448
var first = MySingleton.Instance;
var second = MySingleton.Instance;
Assert.AreSame(first, second);
Upvotes: 6