TestNG Tutorial
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
- TestNG – Hello World Example
Getting started with TestNG, create a simple test case and how to execute it. - TestNG – Configuration Annotations
This example shows you a list of the configuration annotations supported in TestNG. - TestNG – Expected Exception Test
This example shows you how to do the exceptions testing –@Test(expectedExceptions = ?)
. - TestNG – Ignore Test
This example show you how to enable and disable a Test method –@Test(enabled = true)
. - TestNG – Timeout Test
Make sure a test method must be finished within specified time –@Test(timeOut = 5000)
. - TestNG – Groups Test
This example shows you how to do the group testing –@Test(groups= ?)
,@Test(dependsOnGroups - ?)
. - TestNG – Suite Test
This example shows you how to run multiple Test classes withtestng.xml
. - TestNG – Dependency Test
This example shows you how to usedependOnMethods
anddependsOnGroups
to implement the dependency testing. - TestNG – Parameter Test (XML and DataProvider)
This example shows you how to pass parameters into test method, withXML
or@DataProvider
. - TestNG – Parameter Test (DataProvider)
Yet another@DataProvider
example. - TestNG + Selenium – Load Testing
This example shows you how to use Selenium to perform a load test on a website. - TestNG + Spring Integration Example
This example shows you how to test Spring components with TestNG. - JUnit 4 Vs TestNG – Comparison
Detail features comparison between JUnit 4 and TestNG.
Thank you for this tutorial – quick and effective. This is exactly what I was looking for.
Thank you very much !!
Thanks. This is very helpful.
I just want to test file read class with buffered reader. How can I do that?
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
How to proceed for API testing using TestNG ?
hai..this Tutorial very helpful for me..but i dn know how to do compatibility testing in testNG so pls help me..
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.
What kind of bugs? I’m implemented in my projects, don’t find any major flaws.
Can you please explain the working of TestNG with Listeners & Reporters and XSLT Reports.
Hi mkyong, how to mock database with testng .. Am using struts2 framework .. Really got stuck .. Please do guide me ..
can u send the webdriver testcase for validation of registration page.(contains dropdown,editbox,radiobuttons,listbox,buttons.)
Hi yong,
what is the best api for mock testing with testNG?
Thanks,
Manoj
Thank you. This is very helpful!
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…
Can testNG provide the output of on an ANDROID EMulator connected to Eclipse?
Yes