Disabling reporting

Ask general questions here.
User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Disabling reporting

Post by artur_gadomski » 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:
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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Disabling reporting

Post by Support Team » Fri Dec 10, 2010 2:54 pm

Hello Artur,

Your trick should work fine for all 2.X versions, I will add a ReportLevel.None, which will be in V2.3.6.
For 3.0, you can define custom report levels with custom weights (and custom html style) so you can
define anything you like :)

Michael
Ranorex Team
.
Image

anzacthecat
Posts: 31
Joined: Mon Jan 10, 2011 1:05 pm

Re: Disabling reporting

Post by anzacthecat » Fri Mar 04, 2011 11:21 am

Hi, can you give us an example of setting custom report levels?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Disabling reporting

Post by Support Team » Fri Mar 04, 2011 11:48 am

Hi,

Which version of Ranorex are you using?

Regards,
Peter
Ranorex Team
.
Image