Disabling reporting
Posted: Wed Dec 08, 2010 9:17 am
Recently I've come across following problem. I needed to disable reporting for one of my test methods used in one context without making changes to it's use in other context. Suppose you have:
Did you ever had a similar problem? How did you solve it?
public static bool TestMethodA() { //Doing it's own reporting of debug, info success and failure } public static void TestSuiteA() { // Ordinary use of test. Use built in reporting TestMethodA(); // other tests } public static void TestSuiteB() { // Special test suite that needs to handle it's own reporting so that it produces // only one line of test result per run bool successSoFar = TestMethodA(); if (!successSoFar) { Report.Failure("Test failed"); } // other tests Report.Success("Test passed"); }I have tried to use Report.End() but it did not seem to work the way I expected. So my solution to this is: use Report.CurrentReportLevel to set reporting to accept reports of a certain level and up. Second part is use of enumeration trick in C# where there are really int's behind it. So:
public static bool TestMethodA() { //Doing it's own reporting of debug, info success and failure } public static void TestSuiteA() { // Ordinary use of test. Use built in reporting TestMethodA(); // other tests } public static void TestSuiteB() { // Special test suite that needs to handle it's own reporting so that it produces // only one line of test result per run // This tells reporting to accept nothing. Report.CurrentReportLevel = ReportLevel.Failure + 1; bool successSoFar = TestMethodA(); // Restore original reporting Report.CurrentReportLevel = ReportLevel.Debug; if (!successSoFar) { Report.Failure("Test failed"); } // other tests Report.Success("Test passed"); }This works on 2.3.4.I hope Ranorex Team won't break this in future and maybe will think about adding one more enumeration to ReportLevel called None with a highest priority.
Did you ever had a similar problem? How did you solve it?