0

I use Data driven testing feature in MS test framework. [DataSource] attribute specifies table. C# Method is marked as [TestMethod]. It works but sometimes I need to stop execution. For example, table has 100 rows. How to explicitly (prematurely) exit test method (stop the rest of DDT invocations) after some condition, say during invocation of this method for 50-th row?

 [DataSource("System.Data.SQLite", @"Data Source=D:\Test.db;", "TestTableName", 
     DataAccessMethod.Sequential)]
     [TestMethod]
    public void DataTest()
    {
        string userId = Convert.ToString(TestContext.DataRow["userid"]);
        string telephone = Convert.ToString(TestContext.DataRow["telephone"]);
        string email = Convert.ToString(TestContext.DataRow["email"]);

        // .....

        functionThatPerformsAssert(userId, telephone, email);
        // .....

    }
Vlad
  • 1,977
  • 19
  • 44
  • Can you show the testmethod code please? – Pedro G. Dias May 12 '16 at 05:05
  • Sorry - cant add production code. some example added. but unlikely code will add information. – Vlad May 12 '16 at 17:40
  • So, you want to exit (as in abort) the execution of the test? What do you (and MS test) want the result of the test should be "pass or fail"? If you just want it to exit, and fail, throw an exception! – Jocke May 12 '16 at 20:45
  • After failed assert test should be marked as failed and following say 50 records should be skipped. I didn't mentioned that I need exit/terminate the process that supervise test running. So, after test is skipped the normal flow is expected - if there are any test methods enqueued for execution they should be executed. – Vlad May 12 '16 at 22:16

1 Answers1

0

I solved this invoking Assert.Inconclusive from functionThatPerformsAssert() where _skipTest determines whether to skip current row in data driven test and to begin next row:

if (_skipTest)
            Assert.Inconclusive("Test Skipped");
Vlad
  • 1,977
  • 19
  • 44
  • but when i try this after first iteration only my test case stops... i'm using this in the test initialization. – shrot Mar 09 '18 at 09:50