SlideShare a Scribd company logo
1 of 30
JUnit vs TestNG:
ceasefire or the end of
the war?
Oleksiy Rezchykov
October 2013
Who am I?
• Software Engineer
• Last 6 years working with Java
• XP/Agile/Lean practitioner
• Lazy Pragmatic programmer
@twincengray #xpdays_ua
Unit testing
• A method to test smallest possible portion of source
code
• Tests are independent
• Tests are not affecting the state of the application
under test
• Main building block of the TDD
@twincengray #xpdays_ua
TDD
@twincengray #xpdays_ua
JUnit
• Canonical unit testing framework for Java
• Originated from SUnit (SmallTalk)
• One of the first in xUnit family
• Developed by Kent Beck and Erich Gamma
• First versions at year 2000
• Now on GitHub
@twincengray #xpdays_ua
TestNG
• Test Next Generation
• Alternative unit testing tool for Java
• Authored by Cédric Beust
• First version released in 2004
• First version has a lot of out-of-the-box features
which was missing in Junit
@twincengray #xpdays_ua
Runners: JUnit
@twincengray #xpdays_ua
Runners: JUnit
• By default BlockJUnit4ClassRunner is used
• You could add your own features by extending it
@twincengray #xpdays_ua
Runners: TestNG
• TestRunner is used by default
• You can start it with classes or xml configuration
files
• Usually you create base class for tests to add custom
features
• A variety of interceptor interfaces is at your service
@twincengray #xpdays_ua
Cycle: JUnit
Before/after class @BeforeClass/@AfterClas
s (static methods)
Before/after test @Before/@After
@twincengray #xpdays_ua
Cycle: TestNG
Before/after suite @BeforeSuite/@AfterSuit
e
Before/after class @BeforeClass/@AfterClas
s
Before/after test @BeforeMethod/@AfterM
ethod
@twincengray #xpdays_ua
Suites: JUnit
@twincengray #xpdays_ua
Suites: TestNG
Using testng.xml and <suite> tag
@twincengray #xpdays_ua
Groups: JUnit
@twincengray #xpdays_ua
Groups: TestNG
@BeforeSuite/@AfterSuite
@BeforeTest/@AfterTest
@BeforeGroups/@AfterGroups
@BeforeClass/@AfterClass
@BeforeMethod/@AfterMethod
All has groups attribute
@twincengray #xpdays_ua
Groups: TestNG
You can define which groups you want to run using
testng.xml
@twincengray #xpdays_ua
Test dependencies
JUnit:
Since Junit 4.11
@FixMethodOrder(MethodSorters.JVM)
TestNG:
@Test attributes dependsOnGroups,
dependsOnMethods
@twincengray #xpdays_ua
Parameterized tests: JUnit
@twincengray #xpdays_ua
Parameterized tests: TestNG
The values could be passed from testng.xml
@twincengray #xpdays_ua
Parameterized tests: TestNG
@DataProvider annotation could be used.
@twincengray #xpdays_ua
Exceptions: JUnit
• Try/catch with fail()
• Expected attribute of the @Test annotation
• ExpectedException as a @Rule
@twincengray #xpdays_ua
Exceptions: TestNG
@twincengray #xpdays_ua
@Rule
• JUnit feature
• Supported by runners which extends
BlockJUnit4ClassRunner
• Framework extension point
• There is a set of implemented rules (e.g.
ExpectedException)
@twincengray #xpdays_ua
Test run timeout
• TestNG - attribute in @Test annotation
• JUnit – attribute in @Test annotation
@twincengray #xpdays_ua
Running tests in parallel
JUnit:
• Using maven-surefire-plugin
• Gradle Test task attribute maxParallelForks
TestNG:
• <suite> tag has parallel and thread-count attributes
• @Test has threadPoolSize attribute
@twincengray #xpdays_ua
Env. Support
• Eclipse plugin (does not come out-of-the-box)
• IDE plugin (out-of-the-box)
• Gradle support
• Maven support
• Framework support
@twincengray #xpdays_ua
Conclusion
• JUnit has everything for the UNIT testing but could
be extended to do barely everything
• TestNG has more stuff out-of-the-box and is more
“QA oriented”
• Feature comparison table (from RebelLabs):
http://zeroturnaround.com/wp-
content/uploads/2013/07/unit-testing.jpg
@twincengray #xpdays_ua
To read
TestNG:
• http://testng.org/
• http://testng.org/doc/book.html
• http://beust.com/
JUnit:
• https://github.com/junit-team/junit/wiki
@twincengray #xpdays_ua
Presentation and code
• http://www.slideshare.net/mcgray
• https://github.com/mcgray/junit-vs-testng
@twincengray #xpdays_ua
Questions?
@twincengray #xpdays_ua
@twincengray
oleksiy.rezchykov@gmail.com
http://McGray.com.ua

More Related Content

What's hot

What's hot (20)

TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
TestNG
TestNGTestNG
TestNG
 
Test ng
Test ngTest ng
Test ng
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
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 vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
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
 
Test ng
Test ngTest ng
Test ng
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.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
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 

Viewers also liked

Navigating the Incubator at the Apache Software Foundation
Navigating the Incubator at the Apache Software FoundationNavigating the Incubator at the Apache Software Foundation
Navigating the Incubator at the Apache Software Foundation
Brett Porter
 

Viewers also liked (17)

Java Ahead-Of-Time compilation
Java Ahead-Of-Time compilationJava Ahead-Of-Time compilation
Java Ahead-Of-Time compilation
 
TestNGvsJUnit
TestNGvsJUnitTestNGvsJUnit
TestNGvsJUnit
 
Exploratory Testing Basics, Experiences, and Future in SSTC2016
Exploratory Testing Basics, Experiences, and Future in SSTC2016Exploratory Testing Basics, Experiences, and Future in SSTC2016
Exploratory Testing Basics, Experiences, and Future in SSTC2016
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
 
Michael mahlberg exploratory-testing-the_missing_half_of_bdd
Michael mahlberg exploratory-testing-the_missing_half_of_bddMichael mahlberg exploratory-testing-the_missing_half_of_bdd
Michael mahlberg exploratory-testing-the_missing_half_of_bdd
 
Test-case design
Test-case designTest-case design
Test-case design
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Navigating the Incubator at the Apache Software Foundation
Navigating the Incubator at the Apache Software FoundationNavigating the Incubator at the Apache Software Foundation
Navigating the Incubator at the Apache Software Foundation
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
 
Rest assured
Rest assuredRest assured
Rest assured
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
 
What is this exploratory testing thing
What is this exploratory testing thingWhat is this exploratory testing thing
What is this exploratory testing thing
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlow
 
Мелочь пузатая или Объем тест кейса против его содержательности
Мелочь пузатая или Объем тест кейса против его содержательностиМелочь пузатая или Объем тест кейса против его содержательности
Мелочь пузатая или Объем тест кейса против его содержательности
 
10 Benefits of Automated Testing
10 Benefits of Automated Testing10 Benefits of Automated Testing
10 Benefits of Automated Testing
 
QA Fest 2014. Алексей Лупан. Не тест-кейсы красят тестировщика, а...
QA Fest 2014. Алексей Лупан. Не тест-кейсы красят тестировщика, а...QA Fest 2014. Алексей Лупан. Не тест-кейсы красят тестировщика, а...
QA Fest 2014. Алексей Лупан. Не тест-кейсы красят тестировщика, а...
 
Управление тестированием в Agile
Управление тестированием в AgileУправление тестированием в Agile
Управление тестированием в Agile
 

Similar to TestNG vs JUnit: cease fire or the end of the war

Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
tameemahmed5
 

Similar to TestNG vs JUnit: cease fire or the end of the war (20)

Junit
JunitJunit
Junit
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
How we tested our code "Google way"
How we tested our code "Google way"How we tested our code "Google way"
How we tested our code "Google way"
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
Test Infected
Test InfectedTest Infected
Test Infected
 
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
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Automated Testing on Web Applications
Automated Testing on Web ApplicationsAutomated Testing on Web Applications
Automated Testing on Web Applications
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
 
Unit test programming session 1
Unit test programming   session 1Unit test programming   session 1
Unit test programming session 1
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Automation for developers
Automation for developersAutomation for developers
Automation for developers
 
Unit testing in Unity
Unit testing in UnityUnit testing in Unity
Unit testing in Unity
 
Introduction to Protractor - Habilelabs
Introduction to Protractor - HabilelabsIntroduction to Protractor - Habilelabs
Introduction to Protractor - Habilelabs
 
Level Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With TestcontainersLevel Up Your Integration Testing With Testcontainers
Level Up Your Integration Testing With Testcontainers
 
Junit Interview Questions-ppt
Junit Interview Questions-pptJunit Interview Questions-ppt
Junit Interview Questions-ppt
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
New selenium rc
New selenium rcNew selenium rc
New selenium rc
 

More from Oleksiy Rezchykov

More from Oleksiy Rezchykov (11)

Boot in Production
Boot in ProductionBoot in Production
Boot in Production
 
Spring Data: New approach to persistence
Spring Data: New approach to persistenceSpring Data: New approach to persistence
Spring Data: New approach to persistence
 
Spring MVC is still alive
Spring MVC is still aliveSpring MVC is still alive
Spring MVC is still alive
 
Почему это не работает (Записки консультанта)
Почему это не работает (Записки консультанта)Почему это не работает (Записки консультанта)
Почему это не работает (Записки консультанта)
 
Социология Code Review или что делать, елси ваши тестировщики начали писать т...
Социология Code Review или что делать, елси ваши тестировщики начали писать т...Социология Code Review или что делать, елси ваши тестировщики начали писать т...
Социология Code Review или что делать, елси ваши тестировщики начали писать т...
 
Recruitment vs Engineering: Кто виноват? и Что делать?
Recruitment vs Engineering: Кто виноват? и Что делать?Recruitment vs Engineering: Кто виноват? и Что делать?
Recruitment vs Engineering: Кто виноват? и Что делать?
 
!Сделай сам
!Сделай сам!Сделай сам
!Сделай сам
 
Bdd with java_using_concordion_and_selenium_ui_tests
Bdd with java_using_concordion_and_selenium_ui_testsBdd with java_using_concordion_and_selenium_ui_tests
Bdd with java_using_concordion_and_selenium_ui_tests
 
Light weightj2ee developmentusingspring
Light weightj2ee developmentusingspringLight weightj2ee developmentusingspring
Light weightj2ee developmentusingspring
 
Code review psyhology
Code review psyhologyCode review psyhology
Code review psyhology
 
Story Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkStory Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium Framework
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
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
Victor Rentea
 

Recently uploaded (20)

"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 ...
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
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)
 
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
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
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
 

TestNG vs JUnit: cease fire or the end of the war