I am trying to run Telerik Framework Test using NUnit (through visual studio). And I need to initialize some variables before the tests run. I am using [TestFixtureSetUp] and [TestFixtureTearDown] for this. But it seems that these are being executed for each and every [Test] Method ([TestFixtureSetUp] and [TestFixtureTearDown] should be only once!)
public void MyTestInitialize()
SetUpAndTearDown setup = new SetUpAndTearDown();
myDriver = setup.SetupTestEnvironment("ie");
public void Grid()
//code for gird
public void Box()
//code for Box
public void CleanUp()
SetUpAndTearDown teardown = new SetUpAndTearDown();
I am using NUnit - 2.6.2 Visul studio 2010 ultimate
1 Answer, 1 is accepted
answered on 03 Sep 2013, 10:50 AM
I am sorry to hear that you are experiencing this issue.
You are right that if you have structured correctly your tests, what is inside [TestFixtureSetUp] and should be executed only once prior to executing any of the tests in the fixture as you can read in NUnit documentation. Only what is inside [SetUp] and [TearDown] will be executed for every test.
Here's a the way we recommend structuring NUnit tests:
using Core = NUnit.Core;
/// Summary description for TelerikNUnitTest1
public class TelerikNUnitTest1 : BaseTest
#region [Setup / TearDown]
/// Initialization for each test.
public void MyTestInitialize()
#region WebAii Initialization
// Initializes WebAii manager to be used by the test case.
// If a WebAii configuration section exists, settings will be
// loaded from it. Otherwise, will create a default settings
// object with system defaults.
// Note: We are passing in a delegate to the NUnit's TestContext.Out.
// WriteLine() method. This way any logging
// done from WebAii (i.e. Manager.Log.WriteLine()) is
// automatically logged to same output as NUnit.
// If you do not care about unifying the log, then you can simply
// initialize the test by calling Initialize() with no parameters;
// that will cause the log location to be picked up from the config
// file if it exists or will use the default system settings.
// You can also use Initialize(LogLocation) to set a specific log
// location for this test.
// Pass in 'true' to recycle the browser between test methods
Initialize(false, new TestContextWriteLine(Console.Out.WriteLine));
// If you need to override any other settings coming from the
// config section or you don't have a config section, you can
// comment the 'Initialize' line above and instead use the
// This will get a new Settings object. If a configuration
// section exists, then settings from that section will be
Settings settings = GetSettings();
// Override the settings you want. For example:
settings.Web.DefaultBrowser = BrowserType.FireFox;
// Now call Initialize again with your updated settings object
Initialize(settings, new TestContextWriteLine(Console.Out.WriteLine));
// Place any additional initialization here
/// Clean up after each test.
public void MyTestCleanUp()
// Place any additional cleanup here
#region WebAii CleanUp
// Shuts down WebAii manager and closes all browsers currently running
/// Called after all tests in this class are executed.
public void FixtureCleanup()
// This will shut down all browsers if
// recycleBrowser is turned on. Else
// will do nothing.
In order to help you best, please provide us a sample tests against a public website that we can test and give you a solution for this issue.