Is there any way I can run OneTimeSetup and OneTimeTearDown from derived classes really only once for all classes?
e.g. with:
[Category("DerivedTest")]
public class Base
{
public static void Log(string message)
{
YourLogging($"{message}");
}
[OneTimeSetUp]
public void OTSetup() { Log("Onetime Setup"); }
[OneTimeTearDown]
public void OTTeardown() { Log("OneTime Teardown"); }
[SetUp]
public void Setup() { Log(" Setup"); }
[TearDown]
public void Teardown() { Log(" Teardown"); }
}
public class C1 : Base
{
[Test] public void T11() { Log(" T1"); }
[Test] public void T12() { Log(" T2"); }
}
public class C2 : Base
{
[Test] public void T21() { Log(" T1"); }
[Test] public void T22() { Log(" T2"); }
}
I would like to see that OneTimeSetup is called first, then Setup and TearDown for each test and finally OneTimeTearDown. Curently, it's being called for every test class and that means steps are being performed repeatedly.
It's not related only to single inheritance, there are four levels of this. In first, global, users are created for usage by whole suite, then there are areas, which should have some common setup and teardown for tested environment and then test classes setup defines data checked by category.
Actually, it's not breaking anything but still, creating records repeatedly is pretty time consuming operation and would be nice if could be performed only once.
Thanks
T.