Using API for logging and reporting

Class library usage, coding and language questions.
ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

Using API for logging and reporting

Post by ngrishakin » Fri Feb 24, 2017 8:47 pm

I've been experimenting with logging using just the Ranorex API. I am not using Ranorex Studio. My test cases built with NUnit framework. I need some help to incorporate into my test suite Ranorex report that I'm getting after executing record and playback tests fro Rx IDE.
My test project contains multiple .cs files and one or several test cases inside it. For example:
.....
namespace CatalystRnrx
{
[RequiresSTA]
[Category("SetUp Entities")]
[TestFixture]
public class AddNewAContact
{
[TestFixtureSetUp]
public void Init() {...... }
[TestFixtureTearDown]
public void Cleanup() {....}

[Test, Description("Create New Contact")]
public void test_AddNewAContact()
{
Some code. Using Validate() function instead NUnit Assert()
}
}
}

Any examples if they exist are greatly appreciated.
Thanks,
Nik

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

Re: Using API for logging and reporting

Post by Support Team » Mon Mar 13, 2017 8:27 pm

Support has been working with ngrishakin via email, and there is one solution that has to do with creating global setup and teardown methods in the NUnit solution.

Here is a link to the subject on NUnit site:

https://nunit.org/index.php?p=setupFixture&r=2.6.3

Here is what this looks like in code with Ranorex API lines included

Code: Select all

using NUnit.Framework;
using Ranorex.Core.Reporting;
using Ranorex;

namespace NUnitTestProject1
{
    [TestFixture]
    public partial class NUnitTests
    {
        [TestFixtureSetUp]
        public void TestStartup()
        {
            TestReport.Setup(ReportLevel.Info, "MyAmazinglyAwesomeTestReportWithALongLongLongLongName1.rxlog", true);
            TestReport.BeginTestSuite("TestSuite1");
        }

        [TearDown]
        public void TestTeardown()
        {
            TestReport.SaveReport();
            Report.End();
        }
    }
}
Here is what your normal test method files will look like. This has two test methods, but you can create any number of test method files, with any number of test methods inside.

Code: Select all

using NUnit.Framework;
using Ranorex.Core.Reporting;
using Ranorex;

namespace NUnitTestProject1
{
    [TestFixture]
    public partial class NUnitTests
    {
        [Test]
        public void TestMethod1()
        {
            TestReport.BeginTestCase("TestCase1");
            TestReport.BeginTestModule("TestModule1");
            Report.Log(ReportLevel.Info, "First: Compare two numbers", "TestModule1");
            int a = 1; int b = 1;
            Validate.IsTrue(a == b);
            TestReport.EndTestModule();
            TestReport.EndTestCase();
        }

        [Test]
        public void TestMethod2()
        {
            TestReport.BeginTestCase("TestCase2");
            TestReport.BeginTestModule("TestMethod2");
            Report.Log(ReportLevel.Info, "First: Compare two numbers", "TestMethod2");
            int a = 1; int b = 1;
            Validate.IsTrue(a == b);
            TestReport.EndTestModule();
            TestReport.EndTestCase();
        }
    }
}
.
Image