Q:

How can I stop a data-driven coded ui test

Can anyone tell me how to stop iterating on first failure of a data-driven coded ui test?   I have hundreds of iterations and I want to know something failed before having it complete.   Meaning, I don't want to have to wait hours to know that the first iteration has failed.   Is this possible? 
Thanks

A:

I had similar issue and after some research I found that there are two possible solution:
1.  The complicated one - create your own Test Dispatcher with your own custom data adapter by implementing ITestMethodInvoker interface.  There you can run test iteration in the way you wish.  You will also need to override TestContex class to feed your Test Method with DataRows from your data adapter. 
2.  The simplest one - this wont actually stop Visual Studio from iterating through all DataRows in your Data Source but instead of performing the actual test method, Visual Studio will mark it as skipped and move on.  Here is the sample code:
[CodedUITest]
public class MyTestClass
{
    private TestContext testContext;
    private static int countFailedIterations = 0;
    private static string currentMethod = "";

    public MyTestClass()
    {
        if (! currentMethod. Equals(testContext. FullyQualifiedTestClassName))
        {
            // Reset Iteration Count
            countFailedIterations = 0;
            currentMethod = testContext. FullyQualifiedTestClassName;
        }
    }

    [TestInitialize]
    public void MyTestInit()
    {
        if (countFailedIterations > 0)
            Assert. Inconclusive("Stop it, please");
    }

    [TestCleanup]
    public void MytestCleanup()
    {
        if (testContext. CurrentTestOutcome ! = UnitTestOutcome. Passed)
            countFailedIterations++;
    }

    [TestMethod]
    [DataSource("MyDataSource")]
    public void MyTestMethod()
    {
        //Blah Blah Blah
    }

    public TestContext TestContext
    {
        get { return testContext; }
        set { testContext = value; }
    }
}

