SlideShare a Scribd company logo
1 of 18
Data Driven Tests with TestNG
by Matthias Rothe
matthias.rothe@unic.com
Introduction Example
public boolean isBetween(int i, int lower, int upper)
• Checking whether this method behaves as it should
requires executing it with different values for i, with
fixed values for lower and upper
• While the data changes for each execution the actual
test logic is always exactly the same
6/27/2013 2
Data Driven Testing
• Tests depend more on different input and
output data then on different logic
• The code of the test method is fixed
• The test method is invoked several times with
different data
• The data changes with every test method
invocation
• The test logic depends on complex data
structures
6/27/2013 3
Support from Test Frameworks
• JUnit: Doesn‘t support data driven tests easily,
essentially it requires the definition of a new
test method per data set or using the
ParameterizedTest pattern
• TestNG: Supports data driven tests naturally
by allowing data to be injected into the test
method via method parameters
6/27/2013 4
TestNG Data Providers
• @Test(dataProviderClass, dataProvider)
• @DataProvider(name)
• Class given as dataProviderClass must have a static method
annotated with @DataProvider
• Value of @Test.dataProvider must equal value of
@DataProvider.name
• The static method must either return Iterator<Object[]> or
Object[][]
• Each Object[] must contain values matching the test
method parameters
• There are as many test method invocations as there are
Object[] in the Iterator or Object[][]
6/27/2013 5
TestNG Data Providers - Limitations
• All test data is stored in Java classes
– This doesn‘t separate logic from data clearly
– Java classes are inadequate data stores
– Setting up complex data structures can be quite
cumbersome
• There‘s no standard way for loading test data
from other data sources
6/27/2013 6
Data Binding
• Allows to store data where it naturally
belongs: in data files or databases
• Loads data from external data sources and
binds it to Java types
• Each kind of data can be stored in the most
appropriate format
6/27/2013 7
TestNG Data Binding
• Is built on top of the @DataProvider feature
• Introduces new annotations
– @DataBinding
– @TestInput, @TestOutput
• Currently supported data sources:
– CSV, Properties, Text, XML
6/27/2013 8
@DataBinding
• Activates the generic data provider used for
binding data from the data sources
• Can be defined on class and on method level
• Needs to be activated by registering the
TestAnnotationTransformer
– With testng.xml for whole test suites
– In IDE when executing isolated test cases
6/27/2013 9
Meta Data Declaration
• Each test class has an associated
.data.properties file containing the data
source configurations for the test methods
within that test class
• Configurations for different test methods are
differentiated by property key prefixes
6/27/2013 10
XML Data Source
• See format specification of XML files in the
JavaDoc
• Use for complex hierarchical data structures
• Supported Java types
– Primitives including Strings
– Enums
– Java Beans, up to any nesting level
– Lists of primitives and Java Beans
6/27/2013 11
CSV Data Source
• See format specification of CSV files in the
JavaDoc
• Use for tabular test data
• Supported Java types
– Primitives including Strings
– Enums
– Java Beans, but no nested Java Beans
6/27/2013 12
Best Practices
• Implement the toString() method for Java
Beans, so the data contained in them will be
available in test reports
• If you reuse the same data in several test
methods, load it first and store it in memory
6/27/2013 13
Extending TestNG Data Binding
• The framework is plugin based
• The framework core is data source agnostic
• Each data source is a plugin
• New data sources can be easily added by
implementing a new plugin
• New base packages to search for plugins can
be made known with a testng-
databinding.base-packages file
6/27/2013 14
Maven Coordinates
• Group Id: net.sf.testngdatabind
• Artifact Ids:
– testng-databinding-csv
– testng-databinding-properties
– testng-databinding-text
– testng-databinding-xml
• Version: 2.0
6/27/2013 15
Sourceforge
• Project Home:
http://sf.net/projects/testngdatabind
• Important Features
– File download
– Bug reporting
• Complete JavaDoc:
http://testngdatabind.sf.net/apidocs
6/27/2013 16
Additional Resources
• Join the community at
http://facebook.com/TestNGDataBinding
• Watch a screencast at
http://www.screenr.com/ut97
• Read articles concerning TestNG at
http://testngtricks.blogspot.com
6/27/2013 17
6/27/2013 18

More Related Content

What's hot

TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PBAbhishek Yadav
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkBugRaptors
 
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 warOleksiy Rezchykov
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKEAbhishek Yadav
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentationSanjib Dhar
 
Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Gopi Raghavendra
 
IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4Andrey Oleynik
 
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 sdetdevlabsalliance
 

What's hot (20)

TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
 
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
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 
Test ng
Test ngTest ng
Test ng
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)
 
IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4
 
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
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Junit
JunitJunit
Junit
 

Similar to TestNG Data Binding

A Short and Sweet Guide to Test Data Development
A Short and Sweet Guide to Test Data DevelopmentA Short and Sweet Guide to Test Data Development
A Short and Sweet Guide to Test Data DevelopmentEnov8
 
Data Driven Framework in Selenium
Data Driven Framework in SeleniumData Driven Framework in Selenium
Data Driven Framework in SeleniumKnoldus Inc.
 
DATA WAREHOUSE -- ETL testing Plan
DATA WAREHOUSE -- ETL testing PlanDATA WAREHOUSE -- ETL testing Plan
DATA WAREHOUSE -- ETL testing PlanMadhu Nepal
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databaseselliando dias
 
Data Pipeline Installation Quality
Data Pipeline Installation QualityData Pipeline Installation Quality
Data Pipeline Installation QualityGreenM
 
Data Driven Testing
Data Driven TestingData Driven Testing
Data Driven TestingMaveryx
 
Soap UI - Lesson2
Soap UI - Lesson2Soap UI - Lesson2
Soap UI - Lesson2Qualitest
 
Introduction to SoapUI day 2
Introduction to SoapUI day 2Introduction to SoapUI day 2
Introduction to SoapUI day 2Qualitest
 
Testing and Deployment - Full Stack Deep Learning
Testing and Deployment - Full Stack Deep LearningTesting and Deployment - Full Stack Deep Learning
Testing and Deployment - Full Stack Deep LearningSergey Karayev
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQUONTRASOLUTIONS
 
Pa Project And Best Practice 2
Pa Project And Best Practice 2Pa Project And Best Practice 2
Pa Project And Best Practice 2alice yang
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering Madhar Khan Pathan
 
2013 OHSUG - Clinical Data Warehouse Implementation
2013 OHSUG - Clinical Data Warehouse Implementation2013 OHSUG - Clinical Data Warehouse Implementation
2013 OHSUG - Clinical Data Warehouse ImplementationPerficient
 
Weka : A machine learning algorithms for data mining
Weka : A machine learning algorithms for data miningWeka : A machine learning algorithms for data mining
Weka : A machine learning algorithms for data miningKeshab Kumar Gaurav
 
Test data documentation ss
Test data documentation ssTest data documentation ss
Test data documentation ssAshwiniPoloju
 
Data Acquisition and Preprocessing Objective.pptx
Data Acquisition and Preprocessing Objective.pptxData Acquisition and Preprocessing Objective.pptx
Data Acquisition and Preprocessing Objective.pptxharsha221mt017
 
When assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() failsWhen assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() failsMartin Skurla
 
Analytics machine learning in weka
Analytics machine learning in wekaAnalytics machine learning in weka
Analytics machine learning in wekaSudhakar Chavan
 

Similar to TestNG Data Binding (20)

A Short and Sweet Guide to Test Data Development
A Short and Sweet Guide to Test Data DevelopmentA Short and Sweet Guide to Test Data Development
A Short and Sweet Guide to Test Data Development
 
Data Driven Framework in Selenium
Data Driven Framework in SeleniumData Driven Framework in Selenium
Data Driven Framework in Selenium
 
DATA WAREHOUSE -- ETL testing Plan
DATA WAREHOUSE -- ETL testing PlanDATA WAREHOUSE -- ETL testing Plan
DATA WAREHOUSE -- ETL testing Plan
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databases
 
Data Pipeline Installation Quality
Data Pipeline Installation QualityData Pipeline Installation Quality
Data Pipeline Installation Quality
 
Anand Iyer
Anand IyerAnand Iyer
Anand Iyer
 
Data Driven Testing
Data Driven TestingData Driven Testing
Data Driven Testing
 
BigData Testing by Shreya Pal
BigData Testing by Shreya PalBigData Testing by Shreya Pal
BigData Testing by Shreya Pal
 
Soap UI - Lesson2
Soap UI - Lesson2Soap UI - Lesson2
Soap UI - Lesson2
 
Introduction to SoapUI day 2
Introduction to SoapUI day 2Introduction to SoapUI day 2
Introduction to SoapUI day 2
 
Testing and Deployment - Full Stack Deep Learning
Testing and Deployment - Full Stack Deep LearningTesting and Deployment - Full Stack Deep Learning
Testing and Deployment - Full Stack Deep Learning
 
Qtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutionsQtp manual testing tutorials by QuontraSolutions
Qtp manual testing tutorials by QuontraSolutions
 
Pa Project And Best Practice 2
Pa Project And Best Practice 2Pa Project And Best Practice 2
Pa Project And Best Practice 2
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering
 
2013 OHSUG - Clinical Data Warehouse Implementation
2013 OHSUG - Clinical Data Warehouse Implementation2013 OHSUG - Clinical Data Warehouse Implementation
2013 OHSUG - Clinical Data Warehouse Implementation
 
Weka : A machine learning algorithms for data mining
Weka : A machine learning algorithms for data miningWeka : A machine learning algorithms for data mining
Weka : A machine learning algorithms for data mining
 
Test data documentation ss
Test data documentation ssTest data documentation ss
Test data documentation ss
 
Data Acquisition and Preprocessing Objective.pptx
Data Acquisition and Preprocessing Objective.pptxData Acquisition and Preprocessing Objective.pptx
Data Acquisition and Preprocessing Objective.pptx
 
When assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() failsWhen assertthat(you).understandUnitTesting() fails
When assertthat(you).understandUnitTesting() fails
 
Analytics machine learning in weka
Analytics machine learning in wekaAnalytics machine learning in weka
Analytics machine learning in weka
 

Recently uploaded

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

TestNG Data Binding

  • 1. Data Driven Tests with TestNG by Matthias Rothe matthias.rothe@unic.com
  • 2. Introduction Example public boolean isBetween(int i, int lower, int upper) • Checking whether this method behaves as it should requires executing it with different values for i, with fixed values for lower and upper • While the data changes for each execution the actual test logic is always exactly the same 6/27/2013 2
  • 3. Data Driven Testing • Tests depend more on different input and output data then on different logic • The code of the test method is fixed • The test method is invoked several times with different data • The data changes with every test method invocation • The test logic depends on complex data structures 6/27/2013 3
  • 4. Support from Test Frameworks • JUnit: Doesn‘t support data driven tests easily, essentially it requires the definition of a new test method per data set or using the ParameterizedTest pattern • TestNG: Supports data driven tests naturally by allowing data to be injected into the test method via method parameters 6/27/2013 4
  • 5. TestNG Data Providers • @Test(dataProviderClass, dataProvider) • @DataProvider(name) • Class given as dataProviderClass must have a static method annotated with @DataProvider • Value of @Test.dataProvider must equal value of @DataProvider.name • The static method must either return Iterator<Object[]> or Object[][] • Each Object[] must contain values matching the test method parameters • There are as many test method invocations as there are Object[] in the Iterator or Object[][] 6/27/2013 5
  • 6. TestNG Data Providers - Limitations • All test data is stored in Java classes – This doesn‘t separate logic from data clearly – Java classes are inadequate data stores – Setting up complex data structures can be quite cumbersome • There‘s no standard way for loading test data from other data sources 6/27/2013 6
  • 7. Data Binding • Allows to store data where it naturally belongs: in data files or databases • Loads data from external data sources and binds it to Java types • Each kind of data can be stored in the most appropriate format 6/27/2013 7
  • 8. TestNG Data Binding • Is built on top of the @DataProvider feature • Introduces new annotations – @DataBinding – @TestInput, @TestOutput • Currently supported data sources: – CSV, Properties, Text, XML 6/27/2013 8
  • 9. @DataBinding • Activates the generic data provider used for binding data from the data sources • Can be defined on class and on method level • Needs to be activated by registering the TestAnnotationTransformer – With testng.xml for whole test suites – In IDE when executing isolated test cases 6/27/2013 9
  • 10. Meta Data Declaration • Each test class has an associated .data.properties file containing the data source configurations for the test methods within that test class • Configurations for different test methods are differentiated by property key prefixes 6/27/2013 10
  • 11. XML Data Source • See format specification of XML files in the JavaDoc • Use for complex hierarchical data structures • Supported Java types – Primitives including Strings – Enums – Java Beans, up to any nesting level – Lists of primitives and Java Beans 6/27/2013 11
  • 12. CSV Data Source • See format specification of CSV files in the JavaDoc • Use for tabular test data • Supported Java types – Primitives including Strings – Enums – Java Beans, but no nested Java Beans 6/27/2013 12
  • 13. Best Practices • Implement the toString() method for Java Beans, so the data contained in them will be available in test reports • If you reuse the same data in several test methods, load it first and store it in memory 6/27/2013 13
  • 14. Extending TestNG Data Binding • The framework is plugin based • The framework core is data source agnostic • Each data source is a plugin • New data sources can be easily added by implementing a new plugin • New base packages to search for plugins can be made known with a testng- databinding.base-packages file 6/27/2013 14
  • 15. Maven Coordinates • Group Id: net.sf.testngdatabind • Artifact Ids: – testng-databinding-csv – testng-databinding-properties – testng-databinding-text – testng-databinding-xml • Version: 2.0 6/27/2013 15
  • 16. Sourceforge • Project Home: http://sf.net/projects/testngdatabind • Important Features – File download – Bug reporting • Complete JavaDoc: http://testngdatabind.sf.net/apidocs 6/27/2013 16
  • 17. Additional Resources • Join the community at http://facebook.com/TestNGDataBinding • Watch a screencast at http://www.screenr.com/ut97 • Read articles concerning TestNG at http://testngtricks.blogspot.com 6/27/2013 17

Editor's Notes

  1. Separation of logic and data: Also an organizational issue: people working on the data might not be Java developers