如何计算我的通过失败测试用例并在执行结束时打印

时间:2017-07-28 05:33:49

标签: c# asp.net ranorex

我有多个测试用例,我想编写一个可以统计所有失败或通过测试用例的常用方法,并在执行结束时打印总通过和失败测试用例。

3 个答案:

答案 0 :(得分:1)

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);
    }

答案 1 :(得分:0)

您可以实现如下方法,而不是使用类来计算总通过和失败案例:

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);

答案 2 :(得分:0)

添加值为0的2个全局参数(varSuccess,varFail)。 每次根据结果验证任何内容时,只需添加任一值即可。当测试运行完成后,使用这些值执行您想要的任务(例如,将它们写入报告文件,控制台等)。

相关问题