user2797877
user2797877

Reputation: 135

How to Count my pass fail test case and print at the end of execution

I have multiple test cases and I want to write a common method which can count all fail or pass test case and print the total pass and fail test case at the end of execution.

Upvotes: 0

Views: 1548

Answers (3)

nvntkmr
nvntkmr

Reputation: 96

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

Upvotes: 1

Martin
Martin

Reputation: 615

Add 2 global parameters with value 0 (varSuccess, varFail). Everytime you validate anything depending on the outcome just add to the either value. When test run has finished do what ever you want with those values (eg. write them to the report file, console etc).

Upvotes: 0

Chandrasekhar Raman
Chandrasekhar Raman

Reputation: 706

Instead of using a Class to count the total pass and fail cases, you can implement a method like this:

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

Upvotes: 0

Related Questions