Unit Test C# [TestInitialize]
Solution 1:
You can set the variables that you need as fields of the test class and then initialize them in the TestInitialize method.
class Tests
{
// these are needed on every test
APIContext apicon;
XRepository xRep;
Controller controller;
RelevantFactoryModel update;
[TestInitialize]
public void TestInitialize()
{
apicon = new APIContext();
xRep = new xRepository(apicon);
controller = new relevantController(cRep);
controller.Request = new HttpRequestMessage();
controller.Configuration = new HttpConfiguration();
update = new relevantFactoryModel();
}
}
This way the fields can be accessed from every test