J-unit in Selenium

Blog Author


Published Date

10th October, 2020




  • Share this blog :


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 checkboxes setup() & teardown()à click on finish

2Any import statements are activations

J-Unit life cycle [execution flow]:-

2it contains animations like @before,@after,@test, etc.

  • Before:-

It contains a setup method which acts as a precondition

  • @after:-

2It contains a teardown (or)shut down a method that acts as a postcondition.

  • @test:-

2It is responsible to develop the test scenario where it acts as the 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 sequential order.
  • Right-click on project àclick Newà select J unit test caseà implement the class
  • Take one more class and follow the 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 the option to run either a single test or all classes
  • Not having the option to run the specific classes
  • Once the execution is completed it is providing the result in the j-unit section of explain but not in any external field execute for the reporting.
  • All the above limitations can be overcome by using test NG.

Test NG:-

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

Steps to install testing in Eclipse: 2 Go to eclipse à click on help 2 select install new software2 click on add2 give the name on ”Test NG” à provide URL as  -- >click ok à check the checkbox “Test NG”2 click on next2 again next2 click on the radio button “I accept the license”2 click on finish 2 click ok on security warning manage to 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 the project à click on test NG 2 select create Test NG class Click on browse folder on the 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 checkboxes @ 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 animations like @before test, @after test, @test e.t.c

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

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

  • In console

E:  workspace loan selenium test. output default suite default test. Home Result o/p file [external file] XML:-      

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 the 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

About Author


Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .

Related Blogs

Write For Us