我有一个测试用例,需要一个与其余测试分开的竞赛ID,但是仍然使用与先前测试相同的参数。
由于竞赛可以过期,因此我查询以获取当前的raceId,而不是对其进行硬编码。
测试的目的是确保用户可以在同一时间段内参加多个竞赛。玩完第一场比赛后,我希望if语句为raceId分配另一个值。
[TestCase("User1@abc.com", "Pass", TestName = "Contest1 Pass")]
[TestCase("User2@abc.com", "Fail", TestName = "Contest1 Fail")]
[TestCase("User3@abc.com", "Invalid", TestName = "Contest1 Invalid")]
[TestCase("User1@abc.com", "Pass", TestName = "Contest2 Pass")]
public async Task PlayContest(string email, string status)
{
int contestId = 1;
if(TestName == "Contest2 Pass")
{
contestId = 2;
}
//Do work here based on assigned contestId
}
不允许我使用TestName在if语句中定义CompetitionId。有没有一种方法可以区分TestCase值,以便我可以定义方案以为CompetitionId分配不同的值?
谢谢。
答案 0 :(得分:0)
[TestCase("User1@abc.com", "Pass", "Contest1 Pass")]
[TestCase("User2@abc.com", "Fail", "Contest1 Fail")]
[TestCase("User3@abc.com", "Invalid", "Contest1 Invalid")]
[TestCase("User1@abc.com", "Pass", "Contest2 Pass")]
public async Task PlayContest(string email, string status,string testName)
{
int contestId = 1;
if(testName == "Contest2 Pass")
{
contestId = 2;
}
//Do work here based on assigned contestId
}