NUnit is a popular open-source unit testing framework for C#. It is ported from the JUnit framework. It is used for the development and execution of tests with the .NET language. It also facilitates batch execution of tests through console runner (nunit-console.exe). The console runner helps in loading, exploring, and executing tests with the help of NUnit Test Engine.
Here are some of the reasons why testers prefer NUnit framework over other C# test automation frameworks:
Most of the .NET developers use Visual Studio for writing code as it eases the process of test case development, debugging, testing, and maintenance. NUnit Visual Studio Adapter is used to execute NUnit tests as it works with all the current editions of Visual Studio.
Selenium is an open-source test automation framework used for automated cross browser testing. It supports popular web browsers – Firefox, Chrome, Microsoft Edge, Internet Explorer, Safari, etc. To interact with the underlying web browser, a collection of language specific bindings to drive the browser called Selenium WebDriver is used.
Selenium Framework interacts with the web browser through Selenium WebDriver commands that let you automate actions like open, close, maximise the browser window, etc. Selenium Webdriver commands are the methods used to run your Selenium test automation scripts.
NUnit has been supporting parameterized tests since the release of NUnit 2.5. Test methods can have parameters, and various attributes are available that indicate what arguments should be supplied by the NUnit framework. Using special attributes in NUnit, you can develop foolproof tests by verifying them on different browsers, browser versions, and platforms, which can be passed as parameters to the test.
When you are working on unit tests, there are scenarios where you wished that the execution should have stopped but ‘the Assertion,’ was missed. While developing tests using different test frameworks, my fellow developers frequently asked one question: ‘Should I use an assert or an exception in my test code’?
Annotations tell the underlying framework about how the code needs to be interpreted. Annotations in NUnit are added between [ ]. NUnit framework makes use of annotations since it helps in building a more robust framework. It also improves the clarity of the test code since the implementation is under different annotations.
Test reports are an integral part of any testing activity, whether it is automation testing or manual testing. They help track how the activities related to automation testing have evolved over a period of time. The same principle also applies when using NUnit framework for automated browser testing.
Automation tests can be executed at an optimal pace by leveraging parallel execution. This can be achieved if the implemented tests (or test suites) effectively utilize the capabilities offered by automation testing framework (like Selenium) and the testing infrastructure where the tests are run. Parallel execution in Selenium is the starting point for speeding up the test execution, as tests can be run simultaneously across different ‘environments.’