TestNG Test Guide
TestNG Test Guide
TestNG - Overview
Testing is the process of checking the functionality of an application to ensure it works as
per requirements. Unit testing comes into picture at the developer level where adequate
measures are taken to test every single entity (class or method) to ensure the final
product meets the requirements.
JUnit has driven developers to understand the usefulness of tests, especially of unit
tests, when compared to any other testing framework. Leveraging a rather simple,
pragmatic, and strict architecture, JUnit has been able to "infect" great number of
developers. Do take a look at our tutorial on JUnit to have a good understanding of its
features. JUnit, at the same time, has some shortcomings as well, which are listed below
−
Initially designed to enable unit testing only, now used for all kinds of testing.
Intrusive (forces you to extend classes and name your methods a certain way).
What is TestNG?
Definition of TestNG as per its documentation is as follows −
TestNG is a testing framework inspired from JUnit and NUnit, but introducing some new
functionalities that make it more powerful and easier to use.
Eliminating most of the limitations of the older framework, TestNG gives the developer
the ability to write more flexible and powerful tests. As it heavily borrows from Java
Annotations (introduced with JDK 5.0) to define tests, it can also show you how to use
this new feature of the Java language in a real production environment.
Page 2 of 55
TestNG Features
Supports annotations.
Introduces ‘test groups’. Once you have compiled your tests, you can just ask
TestNG to run all the "front-end" tests, or "fast", "slow", "database" tests, etc.
Supports Dependent test methods, parallel testing, load testing, and partial
failure.
Flexible plug-in API.
TestNG - Environment
TestNG is a framework for Java, so the very first requirement is to have JDK installed in
your machine.
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
System Requirement
OS Task Command
OS Output
If you do not have Java, install the Java Software Development Kit (SDK) from
https://www.oracle.com/technetwork/java/javase/downloads/index.html. We are
assuming Java 1.7.0_25 as the installed version for this tutorial.
OS Output
OS Output
Verify Java Installation using the command java -version as explained above.
OS Archive name
Windows testng-6.8.jar
Linux testng-6.8.jar
Mac testng-6.8.jar
OS Description
OS Description
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
With ANT.
From the command line.
Let us invoke using the testng.xml file. Create an xml file with the name testng.xml in
C:\>TestNG_WORKSPACE to execute Test case(s).
C:\TestNG_WORKSPACE>javac TestNGSimpleTest.java
Page 6 of 55
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================
Write the business logic of your test and insert TestNG annotations in your code.
Add the information about your test (e.g. the class name, the groups you wish to
run, etc.) in a testng.xml file or in build.xml.
Run TestNG.
Here, we will see one complete example of TestNG testing using POJO class, Business
logic class and a test xml, which will be run by TestNG.
double appraisal = 0;
} else {
appraisal = 1000;
}
return appraisal;
}
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testCalculateAppriasal() {
employee.setName("Rajeev");
employee.setAge(25);
employee.setMonthlySalary(8000);
Page 9 of 55
employee.setName("Rajeev");
employee.setAge(25);
employee.setMonthlySalary(8000);
Before you can run the tests, you must configure TestNG using a special XML file,
conventionally named testng.xml. The syntax for this file is very simple, and its contents
are as shown below. Create this file in C:\>TestNG_WORKSPACE.
A suite is represented by one XML file. It can contain one or more tests and is
defined by the <suite> tag.
Tag <test> represents one test and can contain one or more TestNG classes.
<class> tag represents a TestNG class. It is a Java class that contains at least
one TestNG annotation. It can contain one or more test methods.
If all has been done correctly, you should see the results of your tests in the console.
Furthermore, TestNG creates a very nice HTML report in a folder called test-output that
is automatically created in the current directory. If you open it and load index.html, you
will see a page similar to the one in the image below −
Annotations were formally added to the Java language in JDK 5, and TestNG made the
choice to use annotations to annotate test classes.
Page 11 of 55
@BeforeSuite
1 The annotated method will be run only once before all tests in this suite have
run.
@AfterSuite
2 The annotated method will be run only once after all tests in this suite have
run.
@BeforeClass
3 The annotated method will be run only once before the first test method in
the current class is invoked.
@AfterClass
4 The annotated method will be run only once after all the test methods in the
current class have run.
@BeforeTest
5 The annotated method will be run before any test method belonging to the
classes inside the <test> tag is run.
@AfterTest
6 The annotated method will be run after all the test methods belonging to the
classes inside the <test> tag have run.
@BeforeGroups
The list of groups that this configuration method will run before. This method
7
is guaranteed to run shortly before the first test method that belongs to any
of these groups is invoked.
@AfterGroups
The list of groups that this configuration method will run after. This method is
8
guaranteed to run shortly after the last test method that belongs to any of
these groups is invoked.
@BeforeMethod
9
The annotated method will be run before each test method.
@AfterMethod
10
The annotated method will be run after each test method.
11 @DataProvider
Marks a method as supplying data for a test method. The annotated method
must return an Object[ ][ ], where each Object[ ] can be assigned the
parameter list of the test method. The @Test method that wants to receive
Page 12 of 55
data from this DataProvider needs to use a dataProvider name equals to the
name of this annotation.
@Factory
12 Marks a method as a factory that returns objects that will be used by TestNG
as Test classes. The method must return Object[ ].
@Listeners
13
Defines listeners on a test class.
@Parameters
14
Describes how to pass parameters to a @Test method.
@Test
15
Marks a class or a method as a part of the test.
Annotations are strongly typed, so the compiler will flag any mistakes right away.
Test classes no longer need to extend anything (such as TestCase, for JUnit 3).
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
Page 13 of 55
import org.testng.annotations.AfterSuite;
// test case 2
@Test
public void testCase2() {
System.out.println("in test case 2");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("in beforeMethod");
}
@AfterMethod
public void afterMethod() {
System.out.println("in afterMethod");
}
@BeforeClass
public void beforeClass() {
System.out.println("in beforeClass");
}
@AfterClass
public void afterClass() {
System.out.println("in afterClass");
}
@BeforeTest
public void beforeTest() {
System.out.println("in beforeTest");
}
@AfterTest
public void afterTest() {
System.out.println("in afterTest");
}
Page 14 of 55
@BeforeSuite
public void beforeSuite() {
System.out.println("in beforeSuite");
}
@AfterSuite
public void afterSuite() {
System.out.println("in afterSuite");
}
C:\TestNG_WORKSPACE>javac TestngAnnotation.java
Now, run the testng.xml, which will run the test case defined in the provided Test Case
class.
in beforeSuite
in beforeTest
in beforeClass
in beforeMethod
in test case 1
Page 15 of 55
in afterMethod
in beforeMethod
in test case 2
in afterMethod
in afterClass
in afterTest
in afterSuite
===============================================
Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
beforeMethod() method executes for each test case but before executing the test
case.
afterMethod() method executes for each test case but after executing the test
case.
On an existing testng.xml.
You can also define which groups to include or exclude, assign parameters, etc. The
command line parameters are −
-target
-groups
-testrunfactory
-listener
We will create the TestNG object an existing testng.xml in our example below.
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>TestNG_WORKSPACE.
/*
* This class prints the given message on console.
*/
//Constructor
//@param message to be printed
public MessageUtil(String message) {
this.message = message;
}
Implement the test condition and check the condition using assertEquals API of
TestNG.
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testPrintMessage() {
Assert.assertEquals(message, messageUtil.printMessage());
}
}
Create testng.xml
Next, let's create testng.xml file in C:\>TestNG_WORKSPACE, to execute test case(s).
This file captures your entire testing in XML. This file makes it easy to describe all your
test suites and their parameters in one file, which you can check in your code repository
or e-mail to coworkers. It also makes it easy to extract subsets of your tests or split
several runtime configurations (e.g., testngdatabase.xml would run only tests that
exercise your database).
Now, run the testng.xml, which will run the test case defined in <test> tag.
Hello World
===============================================
Sample test Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
<suite> is the root tag of your testng.xml. It describes a test suite, which in turn is
made of several <test> sections.
The following table lists all the legal attributes that <suite> accepts.
name
1
The name of this suite. It is a mandatory attribute.
verbose
2
The level or verbosity for this run.
parallel
3
Whether TestNG should run different threads to run this suite.
thread-count
4 The number of threads to use, if parallel mode is enabled (ignored other-
wise).
Page 19 of 55
annotations
5
The type of annotations you are using in your tests.
time-out
6 The default timeout that will be used on all the test methods found in this
test.
In this chapter, we will show you an example having two test classes, Test1 & Test2, to
run together using Test Suite.
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>JUNIT_WORKSPACE.
/*
* This class prints the given message on console.
*/
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
Assert.assertEquals(message, messageUtil.printMessage());
}
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message,messageUtil.salutationMessage());
}
}
Now, let's write the testng.xml in C:\>TestNG_WORKSPACE, which would contain the
<suite> tag as follows −
</test>
</suite>
Now, run the testng.xml, which will run the test case defined in the provided Test Case
class.
Inside testPrintMessage()
Manisha
Inside testSalutationMessage()
Hi!Manisha
===============================================
Suite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================
You can also check the test-output folder. Under the Suite1 folder, you can see two html
files created, exampletest1.html and exampletest2.html, which would look as follows −
Page 22 of 55
If a test method is annotated with @Test(enabled = false), then the test case that is not
ready to test is bypassed.
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>TestNG_WORKSPACE.
/*
* This class prints the given message on console.
*/
//Constructor
//@param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(enabled = false)
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
message = "Manisha";
Assert.assertEquals(message, messageUtil.printMessage());
}
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message, messageUtil.salutationMessage());
}
}
Create testng.xml
Create testng.xml in C:\>TestNG_WORKSPACE to execute test case(s).
Page 24 of 55
Now, run the testng.xml, which will not run testPrintMessage() the test case defined in
provided the Test Case class.
Inside testSalutationMessage()
Hi!Manisha
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================
You can also ignore a group of tests, which will be discussed in the next chapter.
Not only can you declare those methods that belong to groups, but you can also specify
groups that contain other groups. Then, TestNG can be invoked and asked to include a
certain set of groups (or regular expressions), while excluding another set.
Page 25 of 55
Group tests provide maximum flexibility in how you partition your tests, and doesn't
require you to recompile anything if you want to run two different sets of tests back to
back.
Groups are specified in your testng.xml file using the <groups> tag. It can be found
either under the <test> or <suite> tag. Groups specified in the <suite> tag apply to all
the <test> tags underneath.
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>
TestNG_WORKSPACE.
/*
* This class prints the given message on console.
*/
public class MessageUtil {
private String message;
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
}
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = { "checkintest" })
@Test(groups = { "functest" })
Create testng.xml
Create testng.xml in C:\> TestNG_WORKSPACE, to execute test case(s). Here, we
would be executing only those tests, that belong to the group functest.
<groups>
<run>
<include name = "functest" />
</run>
</groups>
<classes>
<class name = "GroupTestExample" />
</classes>
</test>
</suite>
Now, run the testng.xml, which will run only the method testPrintMessage(), as it
belongs to the group functest.
Page 28 of 55
Inside testPrintMessage()
.com
Inside testExitMessage()
www..com
===============================================
Suite1
Total tests run: 2, Failures: 1, Skips: 0
===============================================
Group of Groups
Groups can also include other groups. These groups are called MetaGroups. For
example, you might want to define a group all that includes checkintest and functest.
Let's modify our testng.xml file as follows −
<groups>
<run>
<include name = "all"/>
</run>
</groups>
<classes>
<class name = "GroupTestExample" />
</classes>
Page 29 of 55
</test>
</suite>
Executing the above testng.xml will execute all the three tests and will give you the
following result −
Inside testPrintMessage()
.com
Inside testSalutationMessage()
tutorialspoint.com
Inside testExitMessage()
www.tutorialspoint.com
===============================================
Suite1
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Exclusion Groups
You can ignore a group by using the <exclude> tag as shown below −
<groups>
<define name = "all">
<exclude name = "functest"/>
<include name = "checkintest"/>
</define>
<run>
<include name = "all"/>
</run>
</groups>
<classes>
<class name = "GroupTestExample" />
</classes>
Page 30 of 55
</test>
</suite>
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>
TestNG_WORKSPACE. Add an error condition inside the printMessage() method.
/*
* This class prints the given message on console.
*/
public class MessageUtil {
//Constructor
//@param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(expectedExceptions = ArithmeticException.class)
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
messageUtil.printMessage();
}
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message,messageUtil.salutationMessage());
}
}
</test>
</suite>
Now, run the Test Runner, which will run test cases defined in the provided Test Case
class.
Inside testPrintMessage()
Manisha
Inside testSalutationMessage()
Hi!Manisha
===============================================
Suite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Create a Class
Page 33 of 55
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
message = "Manisha";
Assert.assertEquals(message, messageUtil.printMessage());
}
@Test(dependsOnMethods = { "initEnvironmentTest" })
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message, messageUtil.salutationMessage());
}
@Test
public void initEnvironmentTest() {
System.out.println("This is initEnvironmentTest");
}
}
Create testng.xml
Now, run the testng.xml, which will run the testSalutationMessage() method only after
the execution of initEnvironmentTest() method.
Page 35 of 55
This is initEnvironmentTest
Inside testPrintMessage()
Manisha
Inside testSalutationMessage()
Hi!Manisha
===============================================
Suite1
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Create a Class
Create a java class to be tested, say, MessageUtil.java in C:\>TestNG_WORKSPACE.
// Constructor
// @param message to be printed
public MessageUtil(String message) {
this.message = message;
}
System.out.println(message);
return message;
}
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = { "init" })
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
message = "Manisha";
Assert.assertEquals(message, messageUtil.printMessage());
}
@Test(dependsOnGroups = { "init.*" })
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message, messageUtil.salutationMessage());
}
@Test(groups = { "init" })
public void initEnvironmentTest() {
System.out.println("This is initEnvironmentTest");
}
}
Page 37 of 55
Create testng.xml
Now, run the testng.xml, which will run the testSalutationMessage() method only after
the execution of initEnvironmentTest() method.
This is initEnvironmentTest
Inside testPrintMessage()
Manisha
Inside testSalutationMessage()
Hi!Manisha
Page 38 of 55
===============================================
Suite1
Total tests run: 3, Failures: 0, Skips: 0
===============================================
dependsOnGroups Vs dependsOnMethods
TestNG lets you pass parameters directly to your test methods in two different ways −
With testng.xml
Add test method parameterTest() to your test class. This method takes a string as
input parameter.
Page 39 of 55
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
Create testng.xml
<classes>
<class name = "ParameterizedTest1" />
</classes>
</test>
</suite>
We can also define the parameters at the <suite> level. Suppose we have defined
myName at both <suite> and <test> levels. In such cases, regular scoping rules apply.
It means that any class inside <test> tag will see the value of parameter defined in
<test>, while the classes in the rest of the testng.xml file will see the value defined in
<suite>.
C:\TestNG_WORKSPACE>javac ParameterizedTest1.java
Now, run testng.xml, which will run the parameterTest method. TestNG will try to find a
parameter named myName first in the <test> tag, and then, if it can’t find it, it searches
in the <suit> tag that encloses it.
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================
TestNG will automatically try to convert the value specified in testng.xml to the type of
your parameter. Here are the types supported −
String
int/Integer
boolean/Boolean
byte/Byte
char/Character
double/Double
float/Float
long/Long
short/Short
A Data Provider is a method annotated with @DataProvider. This annotation has only
one string attribute: its name. If the name is not supplied, the data provider’s name
Page 41 of 55
automatically defaults to the method’s name. A data provider returns an array of objects.
The following examples demonstrate how to use data providers. The first example is
about @DataProvider using Vector, String, or Integer as parameter, and the second
example is about @DataProvider using object as parameter.
Example 1
Create a java class called PrimeNumberChecker.java. This class checks if the number is
prime. Create this class in C:\>TestNG_WORKSPACE.
Define the method primeNumbers(), which is defined as a Data provider using the
annotation. This method returns an array of objects.
Add the test method testPrimeNumberChecker() to your test class. This method
takes an Integer and Boolean as input parameters. This method validates if the
parameter passed is a prime number.
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
Page 42 of 55
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@BeforeMethod
public void initialize() {
primeNumberChecker = new PrimeNumberChecker();
}
@DataProvider(name = "test1")
public static Object[][] primeNumbers() {
return new Object[][] {{2, true}, {6, false}, {19, true}, {22, false
}
Create testng.xml
2 true
6 false
19 true
22 false
23 true
===============================================
Suite1
Total tests run: 5, Failures: 0, Skips: 0
===============================================
Example 2
Create a java class Bean.java, which is a simple object with get/set methods, in
C:\>TestNG_WORKSPACE.
Add the test method testMethod() to your test class. This method takes an object
bean as parameter.
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@Test(dataProvider = "test1")
public void testMethod(Bean myBean) {
System.out.println(myBean.getVal() + " " + myBean.getI());
}
}
Create testng.xml
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================
TestNG can automatically recognize and run JUnit tests, so that you can use TestNG as a
runner for all your existing tests and write new tests using TestNG. All you have to do is
to put JUnit library on the TestNG classpath, so it can find and use JUnit classes, change
your test runner from JUnit to TestNG in Ant, and then run TestNG in "mixed" mode. This
way, you can have all your tests in the same project, even in the same package, and
start using TestNG. This approach also allows you to convert your existing JUnit tests to
TestNG incrementally.
import org.junit.Test;
import static org.testng.AssertJUnit.assertEquals;
Now, let's write the testng.xml in C:\>TestNG_WORKSPACE, which would contain the
<suite> tag as follows −
To execute the JUnit test cases, define the property junit="true" as in the xml above. The
JUnit test case class TestJunit is defined in class name.
For JUnit 4, TestNG will use the org.junit.runner.JUnitCore runner to run your tests.
C:\TestNG_WORKSPACE>javac TestJunit.java
Now, run testng.xml, which will run the JUnit test case as TestNG.
Page 47 of 55
===============================================
Converted JUnit suite
TestNG, by default, generates a different type of report for its test execution. This
includes an HTML and an XML report output. TestNG also allows its users to write their
own reporter and use it with TestNG. There is also an option to write your own loggers,
which are notified at runtime by TestNG.
Listeners − For implementing a listener class, the class has to implement the
org.testng.ITestListener interface. These classes are notified at runtime by TestNG
when the test starts, finishes, fails, skips, or passes.
In this chapter, we will have four different examples to demonstrate four different cases
of reporting and logging −
Custom Logging
1
This example illustrates how to write your own logger.
Page 48 of 55
Custom Reporter
2
This example illustrates how to write your own reporter.
JUnit Reports
4
This example illustrates how to generate JUnit reports from TestNG reports.
OS Archive Name
Windows apache-ant-1.8.4-bin.zip
Linux apache-ant-1.8.4-bin.tar.gz
Mac apache-ant-1.8.4-bin.tar.gz
OS Output
OS Description
Page 49 of 55
Windows Append the string %ANT_HOME\bin at the end of the system variable, Path.
OS Archive name
Windows testng-6.8.jar
Linux testng-6.8.jar
Mac testng-6.8.jar
/*
* This class prints the given message on console.
*/
//Constructor
//@param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
Assert.assertEquals(message,messageUtil.printMessage());
}
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message,messageUtil.salutationMessage());
}
}
Then, we'll be using <testng> task in Ant to execute our TestNG test cases.
<path id = "classpath.base"/>
<path id = "classpath.test">
</target>
</project>
C:\TestNG_WORKSPACE\TestNGWithAnt>ant
test:
[testng] [TestNG] Running:
[testng] C:\TestNG_WORKSPACE\TestNGWithAnt\src\testng.xml
[testng]
[testng] Inside testPrintMessage()
[testng] Manisha
[testng] Inside testSalutationMessage()
[testng] Hi!Manisha
[testng]
[testng] ===============================================
[testng] Plug ANT test Suite
[testng] Total tests run: 2, Failures: 0, Skips: 0
[testng] ===============================================
[testng]
BUILD SUCCESSFUL
Total time: 1 second
OS Archive name
Windows testng-6.8.jar
Linux testng-6.8.jar
Mac testng-6.8.jar
We assume you have copied the above JAR file in C:\>TestNG folder.
Open eclipse → right click on the project and go to property → Build Path →
Configure Build Path and add the testng-6.8.jar in the libraries using Add External
Jar button.
We assume that your Eclipse has inbuilt TestNG plug-in; if it is not available, then
please get the latest version using the update site.
Page 54 of 55
In your Eclipse IDE, select Help / Software updates / Find and Install.
Make sure the check box next to the URL is checked and click Next.
Now, your Eclipse is ready for the development of TestNG test cases.
/*
* This class prints the given message on console.
*/
//Constructor
//@param message to be printed
public MessageUtil(String message) {
this.message = message;
}
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public void testPrintMessage() {
Assert.assertEquals(message,messageUtil.printMessage());
}
}
Finally, verify the output of the program by right-clicking on the program and running as
TestNG.