SlideShare a Scribd company logo
TestNG 
Testing code as you write it 
Haritha K
What is TestNG 
A testing framework designed to simplify a 
broad range of development testing needs. 
• Unit testing (testing a class in isolation of the 
others) 
• Integration testing (testing entire systems 
made of several classes, several packages 
and even several external frameworks, such 
as application servers).
What is TestNG? 
• Automated testing framework 
• NG = Next Generation 
• Similar to JUnit (especially JUnit 4) 
• Not a JUnit extension (but inspired by JUnit) 
• Designed to be better than JUnit, especially 
when testing integrated classes 
• Created by Dr. Cédric Beust (of Google) 
• Open source (http://testng.org)
Installing in eclipse 
• The latest version of TestNG can be downloaded from 
http://search.maven.org/ 
• In Eclipse, Select Help / Software updates / Find and Install. 
• Search for new features to install. 
• New remote site. 
• For Eclipse 3.4 and above, enter http://beust.com/eclipse. 
• For Eclipse 3.3 and below, enter http://beust.com/eclipse1. 
• Make sure the check box next to URL is checked and 
click Next. 
• Eclipse will then guide you through the process and restart 
eclipse.
Basic Three steps 
• 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. 
• Run TestNG.
Keywords 
• A suite is represented by one XML file. It can contain 
one or more tests and is defined by the <suite> tag. 
• A test is represented by <test> and can contain one 
or more TestNG classes. 
• A TestNG class is a Java class that contains at least 
one TestNG annotation. It is represented by 
the <class> tag and can contain one or more test 
methods. 
• A test method is a Java method annotated 
by @Test in your source.
Possible configurations in xml file 
• Class names 
• Package names ( will execute all test classes) 
• Groups and methods (include/exclude) 
• run the tests in parallel, how many threads to use 
• TestNG will run your tests in the order they are found 
in the XML file. If you want the classes and methods 
listed in this file to be run in an unpredictable order, 
set the preserve-order attribute to false
Annotations 
@Test 
@BeforeSuite 
@AfterSuite 
@BeforeTest 
@AfterTest 
@BeforeGroups 
@AfterGroups 
@BeforeClass 
@AfterClass 
@BeforeMethod 
@AfterMethod 
@DataProvider 
@Parameters
Assertions 
• assertEquals 
• assertNotEquals 
• assertNotNull 
• assertNull 
• assertSame 
• assertNotSame 
• assertTrue 
• assertFalse 
• fail
Groups 
• Each test method is tagged with any number of groups. 
• @Test // no groups 
• @Test (groups = “group1”) 
• @Test (groups = { “g1”, “g2”, ... }) 
• A group therefore contains any number of test methods. 
• Groups can span classes. 
• Groups can also be externally defined (TestNG xml 
configuration file). 
• A group is identified by a unique string (don’t use white space). 
• There are no pre-defined group names. 
• E.g., “slow”, “fast”, “gui”, “check-in”, “week-end” 
“unit”,“regression”,“integration”,“broken.unknownReason”
Groups continued… 
• TestNG community suggests hierarchical 
names from more general to less. E.g.: 
• database.table.CUSTOMER 
• alarm.severity.cleared 
• Design group names so that you can select 
them with prefix patterns. 
• Groups complement other features
Groups continued… 
You can define groups at the class level and then add groups at 
the method level 
@Test(groups = { “goldenRegression" }) 
public class All { 
@Test(groups = { “regression" ) 
public void method1() { } 
public void method2() { ... }} 
In this class, method2() is part of the group “goldenRegression", 
which is defined at the class level, while method1() belongs to 
both “goldenRegression" and “regression".
Exceptions 
• Methods can have more than one 
exception thrown 
@Test(expectedExceptions = 
NullPointerException.class) 
Or 
@Test(expectedExceptions = 
{ T1.class, ... })
Ignored Test cases 
Enable or disable tests 
• @Test(enabled = false) 
• Add to a group which is excluded 
• Exclude in other ways in testng.xml
Timeout 
• @Test(timeOut = 1000) 
• testng.xml <suite|test> time-out attribute 
• The test case will be failed if time period is 
exceeded
Dependencies 
Sometimes, you need your test methods to 
be invoked in a certain order 
• To make sure a certain number of test 
methods have completed and succeeded 
before running more test methods. 
• To initialize your tests while wanting this 
initialization methods to be test methods as 
well.
Dependency continued 
• fail fast: 
• run Selenium tests only if application was deployed properly, 
• run full system tests only if smoke tests passed, 
• logical dependencies between tests: 
• execute shouldDeleteUserFromDatabase test only 
ifshouldAddUserToDatabase worked 
• Fail fast means that the feedback will be much quicker in case 
of failed tests. 
Logical dependencies gives you a much more realistic error 
information - you learn that 1 tests has failed and 99 has been 
skipped, which is much easier to fix than the information about 
100 failed tests (OMG! what’s going on!? All tests failed)
Parameterized tests 
• In general, it is a good practice, to test your 
code with different sets of parameters: 
• expected values: sqrt(4), sqrt(9), 
• boundary values: sqrt(0), 
• strange/unexpected values: sqrt(-1), sqrt(3)
Parameterized Tests continued 
• Parameterized tests are very simple with 
TestNG. 
• You can have as many data providers in one 
class as you wish. You can reuse them (call 
them from other classes), and you can make 
them "lazy", so each set of parameters is 
created when required.
Parameterized Tests continued 
@Parameters({ "datasource", "jdbcDriver" }) 
@BeforeMethod public void 
beforeTest(String ds, String driver) 
{ m_dataSource = ...; m_jdbcDriver = driver; } 
@DataProvider(name = "test1") 
public Iterator<Object[]> createData() 
{ return new MyIterator(DATA);}
References 
• http://testng.org/doc/index.html 
• http://testng.org/doc/documentation-main.html 
• http://testng.org/testng-1.0.dtd.php 
• http://testng.org/javadoc/
Thank you

More Related Content

What's hot

Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
Nayanda Haberty
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
Edureka!
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
Return on Intelligence
 
Selenium IDE LOCATORS
Selenium IDE LOCATORSSelenium IDE LOCATORS
Selenium IDE LOCATORS
Mindfire Solutions
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Shailendra Chauhan
 
Junit
JunitJunit
JUnit 5
JUnit 5JUnit 5
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
Archana Krushnan
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
Karapet Sarkisyan
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Anirudh Raja
 
Selenium
SeleniumSelenium
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
05 junit
05 junit05 junit
05 junit
mha4
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
Maayan Glikser
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
AbdulImrankhan7
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introduction
Ganuka Yashantha
 

What's hot (20)

Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Selenium IDE LOCATORS
Selenium IDE LOCATORSSelenium IDE LOCATORS
Selenium IDE LOCATORS
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Junit
JunitJunit
Junit
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium
SeleniumSelenium
Selenium
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
05 junit
05 junit05 junit
05 junit
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Hybrid Automation Framework Development introduction
Hybrid Automation Framework Development introductionHybrid Automation Framework Development introduction
Hybrid Automation Framework Development introduction
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 

Viewers also liked

Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
Srikrishna k
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
Naresh Chintalcheru
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
Andrey Oleynik
 
Test ng
Test ngTest ng
Test ng
fbenault
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
ASHIRVAD MISHRA
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
Matthias Rothe
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
Abhijeet Vaikar
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptx
vodqancr
 
Autoscalable open API testing
Autoscalable open API testingAutoscalable open API testing
Autoscalable open API testing
Yevheniia Tymoshchuk
 
Coherent REST API design
Coherent REST API designCoherent REST API design
Coherent REST API design
Frederik Mogensen
 
Page object with selenide
Page object with selenidePage object with selenide
Page object with selenide
COMAQA.BY
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web services
Iurii Kutelmakh
 
Heleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisationsHeleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisations
ForzesNL
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat Application
Micha Kops
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
Bas Dijkstra
 

Viewers also liked (20)

Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
Test ng
Test ngTest ng
Test ng
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptx
 
Autoscalable open API testing
Autoscalable open API testingAutoscalable open API testing
Autoscalable open API testing
 
Coherent REST API design
Coherent REST API designCoherent REST API design
Coherent REST API design
 
Page object with selenide
Page object with selenidePage object with selenide
Page object with selenide
 
Time to REST: testing web services
Time to REST: testing web servicesTime to REST: testing web services
Time to REST: testing web services
 
Heleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisationsHeleen Kuipers - presentatie reinventing organisations
Heleen Kuipers - presentatie reinventing organisations
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat Application
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
 

Similar to testng

Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
Amila Paranawithana
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Devvrat Shukla
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
devlabsalliance
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
Jay Friendly
 
20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...
Will Shen
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
kgayda
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
SumitKumar918321
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
Unit testing
Unit testingUnit testing
Unit testing
Vinod Wilson
 
Software testing part
Software testing partSoftware testing part
Software testing part
Preeti Mishra
 
Unit testing
Unit testingUnit testing
Unit testing
Panos Pnevmatikatos
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementations
Steven Li
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
Chamil Madusanka
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
Aktuğ Urun
 
When assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() failsWhen assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() fails
Martin Skurla
 
Test case management with MTM 2013
Test case management with MTM 2013Test case management with MTM 2013
Test case management with MTM 2013
Raluca Suditu
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 

Similar to testng (20)

Junit
JunitJunit
Junit
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
Test ng
Test ngTest ng
Test ng
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...20070514 introduction to test ng and its application for test driven gui deve...
20070514 introduction to test ng and its application for test driven gui deve...
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Software testing part
Software testing partSoftware testing part
Software testing part
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementations
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
When assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() failsWhen assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() fails
 
Test case management with MTM 2013
Test case management with MTM 2013Test case management with MTM 2013
Test case management with MTM 2013
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 

testng

  • 1. TestNG Testing code as you write it Haritha K
  • 2. What is TestNG A testing framework designed to simplify a broad range of development testing needs. • Unit testing (testing a class in isolation of the others) • Integration testing (testing entire systems made of several classes, several packages and even several external frameworks, such as application servers).
  • 3. What is TestNG? • Automated testing framework • NG = Next Generation • Similar to JUnit (especially JUnit 4) • Not a JUnit extension (but inspired by JUnit) • Designed to be better than JUnit, especially when testing integrated classes • Created by Dr. Cédric Beust (of Google) • Open source (http://testng.org)
  • 4. Installing in eclipse • The latest version of TestNG can be downloaded from http://search.maven.org/ • In Eclipse, Select Help / Software updates / Find and Install. • Search for new features to install. • New remote site. • For Eclipse 3.4 and above, enter http://beust.com/eclipse. • For Eclipse 3.3 and below, enter http://beust.com/eclipse1. • Make sure the check box next to URL is checked and click Next. • Eclipse will then guide you through the process and restart eclipse.
  • 5. Basic Three steps • 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. • Run TestNG.
  • 6. Keywords • A suite is represented by one XML file. It can contain one or more tests and is defined by the <suite> tag. • A test is represented by <test> and can contain one or more TestNG classes. • A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can contain one or more test methods. • A test method is a Java method annotated by @Test in your source.
  • 7. Possible configurations in xml file • Class names • Package names ( will execute all test classes) • Groups and methods (include/exclude) • run the tests in parallel, how many threads to use • TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false
  • 8. Annotations @Test @BeforeSuite @AfterSuite @BeforeTest @AfterTest @BeforeGroups @AfterGroups @BeforeClass @AfterClass @BeforeMethod @AfterMethod @DataProvider @Parameters
  • 9. Assertions • assertEquals • assertNotEquals • assertNotNull • assertNull • assertSame • assertNotSame • assertTrue • assertFalse • fail
  • 10. Groups • Each test method is tagged with any number of groups. • @Test // no groups • @Test (groups = “group1”) • @Test (groups = { “g1”, “g2”, ... }) • A group therefore contains any number of test methods. • Groups can span classes. • Groups can also be externally defined (TestNG xml configuration file). • A group is identified by a unique string (don’t use white space). • There are no pre-defined group names. • E.g., “slow”, “fast”, “gui”, “check-in”, “week-end” “unit”,“regression”,“integration”,“broken.unknownReason”
  • 11. Groups continued… • TestNG community suggests hierarchical names from more general to less. E.g.: • database.table.CUSTOMER • alarm.severity.cleared • Design group names so that you can select them with prefix patterns. • Groups complement other features
  • 12. Groups continued… You can define groups at the class level and then add groups at the method level @Test(groups = { “goldenRegression" }) public class All { @Test(groups = { “regression" ) public void method1() { } public void method2() { ... }} In this class, method2() is part of the group “goldenRegression", which is defined at the class level, while method1() belongs to both “goldenRegression" and “regression".
  • 13. Exceptions • Methods can have more than one exception thrown @Test(expectedExceptions = NullPointerException.class) Or @Test(expectedExceptions = { T1.class, ... })
  • 14. Ignored Test cases Enable or disable tests • @Test(enabled = false) • Add to a group which is excluded • Exclude in other ways in testng.xml
  • 15. Timeout • @Test(timeOut = 1000) • testng.xml <suite|test> time-out attribute • The test case will be failed if time period is exceeded
  • 16. Dependencies Sometimes, you need your test methods to be invoked in a certain order • To make sure a certain number of test methods have completed and succeeded before running more test methods. • To initialize your tests while wanting this initialization methods to be test methods as well.
  • 17. Dependency continued • fail fast: • run Selenium tests only if application was deployed properly, • run full system tests only if smoke tests passed, • logical dependencies between tests: • execute shouldDeleteUserFromDatabase test only ifshouldAddUserToDatabase worked • Fail fast means that the feedback will be much quicker in case of failed tests. Logical dependencies gives you a much more realistic error information - you learn that 1 tests has failed and 99 has been skipped, which is much easier to fix than the information about 100 failed tests (OMG! what’s going on!? All tests failed)
  • 18. Parameterized tests • In general, it is a good practice, to test your code with different sets of parameters: • expected values: sqrt(4), sqrt(9), • boundary values: sqrt(0), • strange/unexpected values: sqrt(-1), sqrt(3)
  • 19. Parameterized Tests continued • Parameterized tests are very simple with TestNG. • You can have as many data providers in one class as you wish. You can reuse them (call them from other classes), and you can make them "lazy", so each set of parameters is created when required.
  • 20. Parameterized Tests continued @Parameters({ "datasource", "jdbcDriver" }) @BeforeMethod public void beforeTest(String ds, String driver) { m_dataSource = ...; m_jdbcDriver = driver; } @DataProvider(name = "test1") public Iterator<Object[]> createData() { return new MyIterator(DATA);}
  • 21. References • http://testng.org/doc/index.html • http://testng.org/doc/documentation-main.html • http://testng.org/testng-1.0.dtd.php • http://testng.org/javadoc/