I use Visual Studio testing tools for unit testing. I need an initialization code to run before each test .
I have a class Setupfor initialization code. I have already added code to run before each test run, using [AssemblyInitialize], but I can’t figure out how to do the same on a single test basis.
I tried using the attribute [TestInitialize], but this only applies to tests in the same file as the method [TestInitialize]. I would like the initialization code to run automatically for all tests in the assembly, without explicitly invoking it in each test file.
[TestClass]
public class Setup
{
[AssemblyInitialize]
public static void InitializeTestRun(TestContext context)
{
}
[TestInitialize]
public static void InitializeTest()
{
}
}