views:

770

answers:

3
+1  A: 

Vyas, I agree with Chad that you're still doing it wrong.

That said, you can look into using the TestContext object.

See http://blogs.msdn.com/vstsqualitytools/archive/2006/01/10/511030.aspx

Chris Lively
Chris,TestContext is not shared amongst TestMethod(s). A new instance of TestContext is provided to each TestMethod (as they're both called on different instances) And this is my primary problem. That's what the code highlights. Apologies for the ambiguity. Or am I missing something here?
Vyas Bharghava
A: 

As Chad had pointed out, it seems that I have no alternative but to use a single test [For once the tool is forcing me to do the right thing ;)] to test the whole flow.

Seems that I could use TestContext.BeginTimer & EndTimer to time each call in the method.

Here's the link to MSDN Forum where I received this answer

Vyas Bharghava
A: 

You can share data between test methods using static members.

For example:

private static List<string> SharedValues = new List<string>();

[TestMethod]
public void TestMethod1()
{
   SharedValues.Add("Awesome!");
}

[TestMethod]
public void TestMethod2()
{
   SharedValues.Add("Thanks for the answer!");
}

[TestMethod]
public void TestMethod3()
{
    Assert.IsTrue(SharedValues.Contains("Awesome!"));
    Assert.IsTrue(SharedValues.Contains("Thanks for the answer!"));
}

Copy this code and create a new ordered test, testing TestMethod1,TestMethod2,TestMethod3. It'll pass!