In testing singleton classes we need the single instance to "go away" after each test. Is there a way to configure nunit to recreate the test app domain after each test, or at least after each fixture?
You could provide the means to renew the singleton instance when testing via a conditional method.
// CUT
public sealed class Singleton{
private static Singleton _instance = new Singleton();
private Singleton()
{
// construct.
}
public static Singleton Instance{
get{
return _instance;
}
}
[Conditional ("DEBUG")]
public static void FreshInstance (){
_instance = new Singleton();
}
}
// NUnit
[TestFixture]
public class SingletonTests{
[SetUp]
public void SetUp(){
Singleton.FreshInstance();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With