Main Tutorials

TestNG Tutorial

testng tutorials

TestNG (Next Generation) is a testing framework which, inspired by JUnit and NUnit, but introducing many new innovative functionality like dependency testing, grouping concept to make testing more powerful and easier to do. It is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc…

1. TestNG Tutorials

References

  1. TestNG Official Website

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
17 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Tom
11 years ago

Thank you for this tutorial – quick and effective. This is exactly what I was looking for.

Colin
3 years ago

Thank you very much !!

Anda
6 years ago

Thanks. This is very helpful.

Domang
8 years ago

I just want to test file read class with buffered reader. How can I do that?

Azeemuddin
8 years ago

Hi MKYong,

Here is my scenario

In My frame work i have “N” Number of test cases. i have one driver class which will controls all the test scripts.

I need to loop through all these testcases until the last test case(Data driven Frame Work using POI).

My condition is :

in my driver script if i am clicking on run then it need to go to the loop and check for the first test case and need to navigate to the first test script and need to execute the first script. once the 1st script completed it need to come to the loop again and need to execute the second script ……like this till end it need to complete all the test scripts.

Here is my loop. it is iterating but it not going to my test script.
for (int i=2; i <= Sheet.getLastRowNum(); i++)
{
if(trueTest.equals(Sheet.getRow(i).getCell(1).getBooleanCellValue()))
{
System.out.println(Sheet.getRow(i).getCell(1).getBooleanCellValue());
String envKey = Sheet.getRow(i).getCell(3).toString();
String browser = Sheet.getRow(i).getCell(4).toString();
if(browser.equals("FF"))
{
driver = new FirefoxDriver();
}
else if(browser.equals("IE"))
{
System.setProperty("webdriver.ie.driver", "D:\GCCOM_FRAMEWORK\Drivers\IEDriverServer.exe");
driver=new InternetExplorerDriver();
}
else
{
browser.equals("CHROME");
{
System.setProperty("webdriver.chrome.driver", "D:\GCCOM_FRAMEWORK\Drivers\chromedriver.exe");
driver = new ChromeDriver();
}
}
String url = environmentURLMap.get(envKey);
driver.get(url);
}
}
}
}

Please suggest me with some code

Sanghamitra
9 years ago

How to proceed for API testing using TestNG ?

mohanapriya
10 years ago

hai..this Tutorial very helpful for me..but i dn know how to do compatibility testing in testNG so pls help me..

Rafael
10 years ago

That said: TestNG has so many bugs and few of them are getting fixed. I generally recommend to not use TestNG if it is not absolutely required.

mkyong
10 years ago
Reply to  Rafael

What kind of bugs? I’m implemented in my projects, don’t find any major flaws.

saurabh shukla
10 years ago

Can you please explain the working of TestNG with Listeners & Reporters and XSLT Reports.

gowtham
11 years ago

Hi mkyong, how to mock database with testng .. Am using struts2 framework .. Really got stuck .. Please do guide me ..

venkatesh
11 years ago

can u send the webdriver testcase for validation of registration page.(contains dropdown,editbox,radiobuttons,listbox,buttons.)

mktyagi
11 years ago

Hi yong,

what is the best api for mock testing with testNG?

Thanks,
Manoj

Venkata
11 years ago

Thank you. This is very helpful!

Sumith
12 years ago

I was using TestNG for running my Silk4J tests. I was able to run the individual tests, but while running as a suit i am facing some issues.

While running as a suit, the methods in the @BeforeMethod and @AfterMethod sections are not working… What might be the reason for this…

Asha
12 years ago

Can testNG provide the output of on an ANDROID EMulator connected to Eclipse?

zain
10 years ago
Reply to  Asha

Yes