nUnit TestFixtureSetup runs for each test

2 posts, 0 answers
  1. sreekanth n
    sreekanth n avatar
    2 posts
    Member since:
    Jan 2010

    Posted 29 Aug 2013 Link to this post

    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
  2. Velin Koychev
    Velin Koychev avatar
    88 posts

    Posted 03 Sep 2013 Link to this post

    Hello Sreekanth,

    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 System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.TestAttributes;
    using ArtOfTest.WebAii.TestTemplates;
    using ArtOfTest.WebAii.Win32.Dialogs;

    using ArtOfTest.WebAii.Silverlight;
    using ArtOfTest.WebAii.Silverlight.UI;

    using NUnit.Framework;
    using Core = NUnit.Core;

    namespace ConfirmDialog
        /// <summary>
        /// Summary description for TelerikNUnitTest1
        /// </summary>
        public class TelerikNUnitTest1 : BaseTest

            #region [Setup / TearDown]

            /// <summary>
            /// Initialization for each test.
            /// </summary>
            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
                // following:


                // This will get a new Settings object. If a configuration
                // section exists, then settings from that section will be
                // loaded

                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

            /// <summary>
            /// Clean up after each test.
            /// </summary>
            public void MyTestCleanUp()
                // Place any additional cleanup here

                #region WebAii CleanUp

                // Shuts down WebAii manager and closes all browsers currently running


            /// <summary>
            /// Called after all tests in this class are executed.
            /// </summary>
            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.

    Looking forward to hearing from you.

    Velin Koychev
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top