I have three test projects. All of them referenced from the Model project:
I created the TestBase class in the Model project and using it as the base class of all test classes. Inheritance looks like this:
[TestClass]
public class UnitTest1 : TestBase
{
[TestMethod]
public void TestMethod1()
{
}
}
In TestBase I have TestInitialize:
[TestInitialize]
public void Initialize()
{
SingletonClass.Initiate();
}
[TestCleanup]
public void Cleanup()
{
//Do some
}
SingletonClass is a static class that needs in tests. I need to initiate it once so I am doing this:
public static class SingletonClass
{
public static bool IsInitiated { get; set; }
public static void Initiate()
{
if (!IsInitiated)
{
IsInitiated = true;
//Do some
Thread.Sleep(5000);
}
}
}
It is working fine when I run tests of one project, but when I run all it is initiating it 3 times(took 15 seconds). Is there any way to run it only once when I run all tests?