What are TestNG and JUnit frameworks in Selenium

15,697

Solution 1

  1. They are tools to help you organize your tests. You can define what you want to run before/after tests, you can group your tests, and reporting on them is made easier.

  2. It is usually mentioned with Selenium because Selenium is a common testing tool. The two work together well, but they are completely separate. (Selenium connects you to your browser, TestNG/JUnit organizes the tests)

  3. Yes. You should be able to pick them up. They are designed to be fairly easy to learn.

Solution 2

JUnit is shipped with most of the IDEs such as Eclipse and NetBeans. There are many testing frameworks being developed using JUnit.

TestNG is an open source framework. It supports parametrization, data driven testing, parallel execution. JUnit is not much flexible for these.

I prefer TestNG over JUnit. I have developed open source testing framework using TestNG for Selenium. You may want to have a look at it.

https://github.com/selenium-webdriver-software-testing/kspl-selenium-helper

Solution 3

JUnit is the basic testing framework that Java uses. It relates to selenium in that if you are doing any testing and you wanted to write the tests with Java, you would use JUnit to write the tests, and hook into Selenium. The answer to your third question is hard to answer. JUnit is java based, so if you know Java, you'll be fine. Assuming that you have a basic understanding of programming, you should be fine.

TestNG is similar to JUnit, but it is not the 'defacto' test framework for Java.

Here are some links that might help:

http://testng.org/doc/index.html

http://junit.org/

Solution 4

You can very well create automated script with the amount selenium and Java knowledge you have. But now, if your manager asks you to run all of your testscript and publish report of pass fail to him. Very primitive way to do this, is add name of your test scripts in excel, get its result by running one by one in eclipse IDE or equivalent and update result in excel.

To avoid this, you can use testNG or junit. TestNG and junit are test framework. One part of automation is developing automation script, another is running it. Junit & TestNG helps in running the automated scripts. which includes, preparing test data, manage it, run tests, publish/store execution report, clear/delete testdata.

You can pick up the TestNG or junit knowledge easily for happy path scenarios. Need to put extra efforts in handling complex situations.

You will also come across terms like Jenkins or CI (Continuous Integration) along with this. Stay Enthusiastic. Its wonderful world of Automation framework.

Share:
15,697
God_Father
Author by

God_Father

Updated on June 11, 2022

Comments

  • God_Father
    God_Father almost 2 years

    I have started learning selenium through YouTube videos and online tutorial..

    I now have knowledge on Creating Classes, Interfaces, Objects, Inheritance, Arrays, Loops in Java.

    As far as Selenium is concerned, I am able automate directly in Selenium using Java language by identifying each elements using Firebug/Firepath tool.

    But I constantly hear about TestNG and JUnit frameworks...

    1. What are these?
    2. How are they related to selenium?
    3. Is it difficult to pick them up with the amount of knowledge I currently possess?
  • God_Father
    God_Father over 10 years
    Ok... Say, I want to open browser > go to Gmail.com > enter uname and password> click login and then signout will my code look different if I dont use any framework(as I am currently) / if I use Junit / if I use testNG
  • God_Father
    God_Father over 10 years
    Oh, i think im getting ur point you are trying to make... so for the same functionaly, I would be writing the same code if I use either junit/TestNG/ I dont use any frame work.. but when I run a Test suite, then each of these will handle things in a different way... am I right here?
  • Nathan Merrill
    Nathan Merrill over 10 years
    If you have a function that is a test, the function will work exactly the same. However, its what happens before/after the function that TestNG/JUnit can help will. If you have 20 tests, and 3 of them fail, it'll keep testing all of the tests when the first one fails, and it'll tell you which tests failed. Basically if you want to organize your tests, you use a framework.
  • Nathan Merrill
    Nathan Merrill over 10 years
    However, it does NOT change anything with how selenium works.
  • BlackHatSamurai
    BlackHatSamurai over 10 years
    Yes, your code will look different compared to Selenium. It also depends on how you are using Selenium. Last time I checked (and this was awhile ago), if you are using the web driver, you have to use JUnit.