user274364
user274364

Reputation: 1857

Testing the existence of single instance -Singleton-C#

How to write test in Nunit to test that only one instance is created by my singleton class.

Upvotes: 1

Views: 403

Answers (2)

Dror Helper
Dror Helper

Reputation: 30819

Create the object twice and use Assert to make sure they have the same reference

Upvotes: 1

Randolpho
Randolpho

Reputation: 56448

var first = MySingleton.Instance;
var second = MySingleton.Instance;
Assert.AreSame(first, second);

Upvotes: 6

Related Questions