views:

80

answers:

2

Hi, I am trying to Unit Test the application using VSTS 2008 unit Testing. My Problem is: I want to invoke two test case in an order. I am using the ordered Test case feature of VSTS 2008 for this. Problem i facing is I increment the value of one variable(X) in TestA and on the basis of that value i am chekcing something in TestB. But when the control comes into TestB, I get the initial value of the X but not that which was incremented in TestA. I think for every test vsts create a new instance of the test class in memory. Please suggest a solution to this except use of STATIC variables.

Code for the same is as below

   [TestMethod()]
   public void ff()
    {
        i = 11;
    }

    [TestMethod()]
    public void gg()
    {
        if (i == 4)
        {

            System.Diagnostics.Debug.WriteLine("it is 4");
        }

        else
        {
            System.Diagnostics.Debug.WriteLine("it is 7");
        }
    }

Thanks in Advance

+1  A: 

Is it possible to redesign your tests in a way that each one can be run separately? This is the correct way to test in 99% of cases. While it does increase overhead a bit, and you may be duplicating your setup a bit, it is far easier to maintain, and each test can focus on it's single function, without worrying about environmental changes.

chills42
A: 

run your orderedtests using the TestView window under Test>Windows.

clicking run all tests in the solution will cause your orderedtests to run out of order

mirezus