I have dependent test cases in my suite. If my first test fails it marks all other test as fail as well. So at the end it show that all all the test cases has failed which is not true.
Is there a way though which I can mark the test as 'failed due to dependent test failure' or something else so that it shows that it failed because the dependent test failed. Is there a way to add a new state in test instead of only have pass, fail, not executed states.
I have added a common flag in our tests which marks the tests as failed when any dependent test fails. As you can see in the code below. It marks the test as Assert.Fail inside else part if the previous test has failed. Is there a way to mark it in some other state and not failed for example : 'Failed due to dependent test failure'.
bool hasPreviousTestCasePassed = false
[TestMethod]
public void DemoTest1()
{
try
{
////perform all the test steps
hasPreviousTestCasePassed = true;
}
catch (Exception ex)
{
hasPreviousTestCasePassed = false;
}
}
[TestMethod]
public void DemoTest2()
{
try
{
if (hasPreviousTestCasePassed)
{
///perform all the test steps and mark flag as true after all steps
hasPreviousTestCasePassed = true;
}
else
{
Assert.Fail("Execution for " + TestContext.TestName + " is aborted as the previous test case failed.");
}
}
catch (Exception ex)
{
hasPreviousTestCasePassed = false;
}
}
Expected result would be to have a way to mark a test as Failed due to dependent test failure and not just mark it as failed.
The Idea behind doing this is that when my first test fails then it marks all the test as failed and the outcome says that all the test has been fail which is not actually true because they got executed.
So I want a way to show case the dependent failure in a separate state so that the results are more clear.
Aucun commentaire:
Enregistrer un commentaire