In my work, we pass an argument to the TestInitialize method to determine how we want the initialization work to work.
public partial class CommonActions { public void TestInitialize(bool adminTest) { try { if (adminTest) { //do stuff }
Then we have standard initialization in the class definition, which defaults to false.
[TestClass] public class ProjectTestBase : FrameworkTestBase { public CommonActions common { get; set; } = new CommonActions(); [TestInitialize] public void TestInitialize() => common.TestInitialize(false);
Then in the tests themselves you can override TestInitialize for any test you want.
[TestClass] public class SetReportsInAdmin : ProjectTestBase { [TestInitialize] public new void TestInitialize() => common.TestInitialize(true);
We use a boolean to determine if there is an administrator test that needs to have extra overhead to configure. Take this and apply whatever variables you want, in such a way as to give you multiple initializations using a single method.
Tim poindexter
source share