Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I need to use NUnit with Selenium WebDriver?

I'm just getting started with Selenium, using VS2012 and C#. I'm not sure if using a separate testing framework such as NUnit or HtmlUnit is necessary. I tried out the google search example that is available online in C# without using NUnit and it worked fine.

So my question at this point is, why would i need to use NUnit with Selenium?

like image 298
neuDev33 Avatar asked Dec 27 '22 08:12

neuDev33


1 Answers

You don't NEED to use NUnit (or any other unit testing framework) with Selenium if you don't want to. However, there may be instances where you might want to use NUnit (or others) to leverage the benefits of other things. For example:

  • If you have existing unit tests it keeps everything in one place. (If that's the way you want to organise things)
  • If you already use NUnit (or your preferred unit testing framework) for unit tests then you can re-use the same test runner (e.g. NUnit console, NUnit GUI, ReSharper, etc.) you use for NUnit meaning you can run all your tests (NUnit and Selenium) with one button press/keyboard shortcut.
  • If you use continuous integration it can run your selenium tests through the existing NUnit (or which ever you prefer) test runner which means you don't have to configure your continuous integration server for the selenium tests separately.

The above assumes that you have unit tests already. If you don't already have unit tests, or you are only interested in the Selenium tests (For example, we have a development team and a tester, we write unit tests, the tester writes Selenium tests and they are run independently of each other) then there is no need to add that extra layer.

Unit tests frameworks and selenium test for different things. Unit tests typically look at a single unit of code at a time (although in practice, I find it often spills out into adjacent units especially if they are small and deterministic). Selenium looks at a web page (or series of pages) as a single test. Selenium's tests need a system to have many of its components integrated together to run the test. It is therefore testing at a higher level as it is checking many things at once. (e.g. that the system can cope with requests, that the responses arrive back, that the responses contain the expected data, that pressing buttons on the page do the correct things, go to the correct pages, etc.)

Ultimately, just because you can do something doesn't mean you should. Running Selenium tests through a unit testing framework is a convenience if you have to handle both. It may work for you, it may not.

like image 130
Colin Mackay Avatar answered Jan 10 '23 07:01

Colin Mackay