Basically I have a test with loads of [TestMethods], This is all well and good but I need to initialize some variables and I want to do it every time the Test runs and not make a [TestMethod] which I have to call to do it.
Can this be done?
Basically I have a test with loads of [TestMethods], This is all well and good but I need to initialize some variables and I want to do it every time the Test runs and not make a [TestMethod] which I have to call to do it.
Can this be done?
What you want to use is
[TestInitialize]
/**
* Runs at the beginning and only once
**/
public void Initialize()
{
}
Tha will run at the start of your test, or before you run the first test method from that test.
As well at [TestInitialize], Coded UI tests also allow for methods to have [ClassInitialize] and [AssemblyInitialize] attributes allowing additional places for initialization. There are also [TestCleanup], [ClassCleanup] and [AssemblyCleanup] attributes available for methods to clean up after tests run.
An additional level of initialization and clean up is possible via the ".testsettings" files. To create a .testsettings file, right click on the solution (not the project) in Solution Explorer, select Add => New Item. You would also have to select the .testsettings file via Menu => Test.