Group Discounts available for 3+ students and Corporate Clients

J-unit in Selenium

Introduction to Junit in Selenium

2It is a java unit testing framework

2The purpose of J unit is to write the test scripts in java programming language and scripts can be executed by default

** write a program to register and login into by using j unit ?

2Right click on the project àclick on new àselect J unit test cases

2Give the package name as “ j unit “ & class name as “mail tag,x-right”

2check the check boxes setup() & teardown()à click on finish

2Any import statements are activations

J-Unit life cycle [execution flow]:-

2it contains the anirations like @before,@after,@test etc.

  • Before:-

It contains a setup method which acts like a precondition

  • @after:-

2It contains teardown (or)shut down method which acts as a post condition.

  • @test:-

2It is responsible to develop the test scenario where it acts like a main method

2For each and every scenario we need to develop with test animation.

2when we run the script initially it invokes @before, @after, @test methods .

  • The same process will be continued for all the @ test methods.
  • once the execution is done it provides the results under the J-unit section.
Inclined to build a profession as Selenium Developer? Then here is the blog post on 
Selenium Training Videos.

Batch execution/suite execution:

2combination of multiple test cases [scenarios]is known as a batch or test suite

  • Take how classes and execute both the classes methods in a sequential order.
  • Right click on project àclick Newà select J unit test caseà implement the class
  • Take one more class and follow above steps
  • To run all the classes right click à click on run as à select run configuration
  • Select the radio button “run all test in the…” à click on apply à click on run

Limitations of J-unit:-

2It is having very limited annotations like @before class, @before, @test, @after ,after class

  • Each and every test @before will be applicable
  • It is having option to run either a single test or all classes
  • Not having option to run the specific classes
  • Once the execution is completed it is providing the result in j-unit section of explain but not in any external field execute for the reporting.
  • All the above limitation can be overcome by using test NG.

Test NG:-

  • It is testing framework inspired and advance version of J-unit.
  • The limitation which are in J-unit are overcome and added new features that mode test NG more power here and easier to use.
  • Test NG is an add-on for eclipse.

Steps to install testing in Eclipse:

2 Go to eclipse à click on help 2 select install new software2 click on add2 give name on ”Test NG” à provide URL as  — >click ok à check the check box “Test NG”2 click on next2 again next2 click on radio button “I accept the license”2 click on finish 2 click ok on security warning manage 2 click yes in restart message

* Write a program to handle the pop –up in spice by using web driver with testing *

2 Take a Test NG class by right click on he project à click on test NG 2 select create Test NG class

Click on browse folder on source folder expand the project and select “SRC” then click on ok

Give the package name on “spice jet _ Test NG”

Give the class name on “spice jet _ popup”

Check the check boxes @ before test and @ After test

Click on finish

Learn more about Selenium Interview Questions in this blog post.

Test NG life cycle[execution flow] :-

2It contains multiple anitations like @before test, @after test, @test e.t.c

2when we run the scripts initially it invokes @before test method then executes an the @test methods in a alphabetical order finally it executes @after test method.

2once the execution is done it provides the results in two formats .

  • In console

E:\  work space loan\ selenium \ test. output \ default suite\ default test. Home

Result o/p file [external file]


2To perform the test scripts execution we are planning to use xml files.


2we can run the test methods in user defined order [we can avoid alphabetical order issue]

2we can perform batch execution

2we can provide user defined names to default suite folder and default test html file.

How to create on XML file:

Go to file 2 click on new 2 select other à expand XML folder 2 select XML file 2 click on next 2  select the project

 Xml file Format:-

<suite name =”spicejet suite” >

<test name=”spicejet test results” >


<class name=”spicejet-testing.spicejet-popup”>


<include name=”verifyone way search”> </include>

<include name=”verify javascripttest”></include>






For an Indepth knowledge on Selenium, click on below

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at, we will update the article in 24 hours.”

0 Responses on J-unit in Selenium"

Leave a Message

Your email address will not be published. Required fields are marked *


Please Enter Your Details and Query.
Three + 6