Working with TestNG - Starters Guide

Working with JUnit tests in TestNG

TestNG provides an option to shift to JUnit test, TestNG can automatically identify and execute Junit tests. User can execute already created JUnit test cases using TestNG.

Let's check this example to understand it better

Create JUnit Test Case Class:

package jUnit;

import org.junit.Test;

public class JunitDemo1 {

	public void method1() {
		System.out.println("Welcome to JUnit");

Create testing.xml file as shown below.

Note: Here we need define the property junit="true" in testing.xml file to execute the JUnit test cases as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite for conversion">
    <test name="JUnit test case" junit="true">
            <class name="jUnit.JunitDemo1"/>

Run the testing.xml file by click on run button in eclipse.

The Output is:

JUnit tests from testNG

So you can see that its as simple as setting an additonal attribute junit="true" in test case element under testing.xml, which allows to testNG to make a switch over to JUnit automatically.


This tutorial is focused on getting you started on TestNG, the testing framework inspired from JUnit and NUnit. Here is a quick table of contents

  1. What is TestNG?
  2. Environment Set-up
  3. Writing Tests
  4. Basic Annotations
  5. Execution Procedure
  6. Executing Tests
  7. Suite Test
  8. Ignore Test
  9. Group Test
  10. Exception Test
  11. Dependency Test
  12. Parametrized Test
  13. JUnit Tests
  14. Test Reports
  15. Running tests without Eclipse
  16. Plugin with ANT




A computer capable of running Java. IntelliJ Community IDE is also required for this course.


Good knowledge of Java programming language and eclipse is essential.


Students looking to get started with TestNG

Learning Objectives

This tutorial will get you started with TestNG.

Author: Subject Coach
Added on: 12th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!