Home United States USA — software How to Generate Test Reports in NUnit

How to Generate Test Reports in NUnit

195
0
SHARE

In this tutorial, you will learn about generating reports in NUnit along with some new features and advantages of Extent Reports.
Join the DZone community and get the full member experience. Test reports are an integral part of any activity related to testing, whether it is automation testing or manual testing. Test reports help track how the activities related to automation testing have evolved over a period of time. The same principle also applies when using NUnit/xUNit/MSTest for automated browser testing. Of the lot, NUnit is the most-used test automation framework for all. Net languages. NUnit reports can serve as a considerable value addition to the tests performed using the said framework. Let’s look at NUnit report generation and how seamlessly you can integrate the NUnit reporting tool in the test implementation. As far as Selenium C# is concerned, Extent and Allure are the preferred NUnit reporting tools. Both are third-party tools that have to be installed from the NuGet gallery, either from the Visual Studio UI or using the Package Manager Console commands. Extent Report is a more popular NUnit report generator. By the end of this blog, you would be comfortable integrating Extent Reports in the Selenium C# test implementation. So, let’s get started. ExtentReport is a popular multi-language test reporting tool that gives in-depth information about the status of the tests. The Extent framework lets you create interactive and detailed test reports. Apart from the. NET framework, ExtentReport is also available for the Java language. ExtentReports (or Extent Reports) is an open-source reporting library, and version 4.0 of ExtentReports is licensed under Apache 2.0. The Extent Framework source code is available on GitHub; the implementation of ExtentReports 4. NET Core is available here. As of writing this article, ExtentReports 4.0 was the latest version of ExtentReports for the. NET framework. Since ExtentReports 3.x is no longer maintained, it is recommended to migrate from ExtentReports 3.x to ExtentReports 4.x. In case you are using SpecFlow for automation testing with Selenium C#, you have the flexibility to integrate ExtentReports 4.x in the SpecFlow BDD tests for HTML test report generation. Extent Reports follows a freemium pricing approach, which essentially means that it is available in Community (or Free) and Pro (or Paid) Editions. As per the official documentation of ExtentReports, there are no differences in the underlying ExtentReports API. The community & pro users can leverage the advantage of features offered by full-featured APIs. For the demonstration, we have used the Community Edition of ExtentReports 4.x. There are several advantages of using Extent Reports; the major ones are below: Easy to setup and integrate ExtentReports with Selenium C# frameworks like NUnit, MSTest, and xUnit and Selenium Java frameworks like TestNG, JUnit, etc. Helps generate super-customizable HTML test reports that help visualize the status of the tests executed on the Selenium Grid. Stepwise and Pie-chart representations in the NUnit test report provide top-level information on how the tests have fared (i.e., how many passed/failed) on the execution front. It lets you customize the report’s look & feel through an XML-based configuration file where you can input details such as report theme (Standard/Dark), report title, document title, etc. It makes it easy to track multiple test cases that are a part of a single test suite. It can be used with ease even when the test scenarios are executed parallel on a Selenium Grid. Each test case is accompanied by vital information like logs, results, and the overall time to execute the test. It lets you capture the ScreenShot with every test step. The captured ScreenShots can help identify the exact step at which the test has failed. Methods OnNodeAdded, OnTestStarted, OnScreenCaptureAdded, etc., let you perform actions (e.g., adding relevant logs) when that particular ‘event’ (i.e., test has started, screenshot is captured, the test is removed, etc.) has occurred in the tests. Extent Reports 4 is a significant upgrade over Extent Reports 3, as a lot of new features are introduced in version 4.x of ExtentReports. In case you are currently using Extent Reports 3 as the NUnit reporting tool, you might want to upgrade to Extent Reports 4. In Extent Reports, vital related information like tests, nodes, events, and assignment of tags, devices, environment values, etc., can be printed to ‘multiple destinations.’ These destinations are referred to as ‘reporter.’ Here are the major feature upgrades in Extent Reports 4, most of which are also available for Community Edition of this NUnit report generator: Extent Reports 4 provides reporters for BDD/Gherkin, non-BDD, and both. Here are some of the reporters available with Extent Reports 4: ExtentAventReporter ExtentBDDReporter ExtentCardsReporter ExtentTabularReporter, and many more. LoggerReporter that eases the navigation from Category (or Bug) view to the Test view. Provision for adding base64 screenshots to logs through the CreateScreenCaptureFromBase64String method of MediaEntityBuilder class. Numerous layout improvements for the BDD view. Support for adding a Gherkin dialect other than ‘en’ or English keywords. The API for setting the dialects is inline with the dialect defined in the Gherkin spec. For example, you can set the Gherkin dialect to German (or de) by using the command extent. GherkinDialect = “de”; in the test code. The ExtentHtmlReporter method, which is newly introduced in Extent Reports 4, is used for creating HTML reports. ExtentV3HtmlReporter method was earlier used for creating HTML reports with Extent Reports 3. For migrating from ExtentReports 3 to ExtentReports 4, it is recommended to remove ChartLocation from the setup code as it is no longer available in Extent Reports 4. The Extent framework follows an Observer pattern where the reporter (e.g., ExtentHTMLReporter) attached to the framework becomes an ‘observer’ and is notified of changes like the creation of logs and logs, etc. Some of the notified changes result in content updation in the report. Though the Extent framework offers numerous capabilities, we would require only certain classes for report generation in NUnit. Here are the two major classes that are frequently used when creating NUnit report using the Extent framework: ExtentHtmlReporter (for version 4.x) or ExtentV3HtmlReporter (for version 3.x) ExtentReports ExtentTest MediaEntityBuilder We would be using the ExtentHtmlReporter method in the code as our demo will be with ExtentReports 4. The ‘ExtentHtmlReporter’ class The ExtentHtmlReporter class is used for generating Extent Report in the HTML format in the path specified as the argument. It supports two reporter configurations – Default and SPA (Single-Page Applications). It also provides the flexibility to load the report configurations from a configuration XML file.

Continue reading...