C# 如何计算通过-失败测试用例并在执行结束时打印
我有多个测试用例,我想编写一个通用方法,可以计算所有失败或通过的测试用例,并在执行结束时打印总通过和失败的测试用例。您可以实现如下方法,而不是使用类来计算总通过和失败的案例:C# 如何计算通过-失败测试用例并在执行结束时打印,c#,asp.net,ranorex,C#,Asp.net,Ranorex,我有多个测试用例,我想编写一个通用方法,可以计算所有失败或通过的测试用例,并在执行结束时打印总通过和失败的测试用例。您可以实现如下方法,而不是使用类来计算总通过和失败的案例: int pass=0; int fail=0; for(int i=0;i<testCasescount;i++) { //read the input using Console.ReadLine(); //check whether the test case is a pass or fail and
int pass=0;
int fail=0;
for(int i=0;i<testCasescount;i++)
{
//read the input using Console.ReadLine();
//check whether the test case is a pass or fail and appropriately increment the counter
}
//executed after the for loop i.e. all the test cases
Console.WriteLine(pass);
Console.WriteLine(fail);
int pass=0;
int fail=0;
对于(int i=0;i添加2个值为0的全局参数(varSuccess,varFail)。
每次根据结果验证任何内容时,只需将其添加到任意一个值。测试运行完成后,可以对这些值执行任何操作(例如,将它们写入报表文件、控制台等)。public List GetUserDetails(int i){ClassProperty userinfo=new ClassProperty();//userinfo.Name=i.ToString();userinfo.Pass=i;//userinfo.Fail=1;classproperty.Add(userinfo);返回classproperty;}class classproperty{public int Pass{get;set;}public int Fail{get;set;}实际上我有多个类,因为有多个测试用例,所以我如何计算所有通过和失败的测试用例。
int Failed = 0;
int Passed = 0;
var TestCases = TestSuite.Current.SelectedRunConfig.GetActiveTestContainers();
foreach(var testcase in TestCases){
{if(testcase.IsTestCase){ //To Handle Smart Folders
if(testcase.Status.ToString()=="Failed")
{
Failed++;
}
Passed++;
}
}
}
Report.Log(ReportLevel.Info, "Passed Count :"+Passed);
Report.Log(ReportLevel.Info, "Failed Count :"+Failed);
}