Scenario. Language C#, Unit testing using VS2008 Unit testing framework
I have a static class with a static constructor and 2 methods. I have 4 test methods written to test the entire class. My Static Constructor has some important initializations.
Now if I run all the 4 unit test cases in tandem, the static constructor will be called only at the beginning. At the end of each test case, there is no such thing
called static destructor, So the state info in the constructor gets carried to the next unit test case also. What is the workaround for this.
Type staticType = typeof(StaticClassName);
ConstructorInfo ci = staticType.TypeInitializer;
object[] parameters = new object[0];
ci.Invoke(null, parameters);
from http://colinmackay.scot/2007/06/16/unit-testing-a-static-class/
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