I have a test case where I included a step that applies to all markets I run this against but one. I would like to skip this step in this scenario.
This is what I am currently doing, but I am wondering if there is a built in function. I have searched and I am not having much luck, thanks.
[Then(@"Verify Yearly AutoOrder was created from enrollment")]
public void ThenVerifyYearlyAutoOrderWasCreatedFromEnrollment()
{
if (!Market.Equals("in"))
{
this.srEnrollPage.VerifyYearlyAutoOrderWasCreatedFromEnrollment(this.dataCarriers.orderNumber, this.dataCarriers.userEmail);
}
else
{
return; // India does not have yearly autoOrders as of now.
}
}
CodePudding user response:
There are two things that make me nervous about "skipping" a step.
From a behavior-driven development perspective, India deserves its own scenario explicitly stating that auto orders are not created:
Scenario: Auto orders are not created in India after enrollment
Given the market is "India"
And ...
When something about enrolling
Then a yearly auto order should not be created from the enrollment
This new step would assert something to the effect of:
this.srEnrollPage.VerifyYearlyAutoOrderWasNotCreatedFromEnrollment(...);
// ^^^
This is all fine if practicing real behavior-driven development. I understand that many people use Gherkin/SpecFlow as an automation framework for QA testing. In that case, consider making the opposite assertion for India:
[Then(@"Verify Yearly AutoOrder was created from enrollment")]
public void ThenVerifyYearlyAutoOrderWasCreatedFromEnrollment()
{
if (Market == "in")
{// ^^
this.srEnrollPage.VerifyYearlyAutoOrderWasNotCreatedFromEnrollment(...);
// ^^^^^^
}
else
{
this.srEnrollPage.VerifyYearlyAutoOrderWasCreatedFromEnrollment(...);
// ^^^
}
}
Simply passing the scenario or skipping the step could hide problems with the application if it suddenly starts creating auto orders for India. I would want a failing test if some developer ignored this business rule and created the orders anyhow. With your suggestion, the test would pass even if an auto order gets mistakenly created for India.
The assertion should always assert something. If you cannot assert the auto order was created, at least assert the auto order wasn't created, so you can catch application failures instead of accidentally hiding them.
Don't assume India does not get auto orders. Prove it by making the appropriate assertion.
CodePudding user response:
You can use simply Assert.Pass();
but consider rewriting the tests to cover the scenarios (as @greg-burghardt said).