SlideShare a Scribd company logo
What is JUnit? | Edureka
What is JUnit? Advantages and uses
Features
The JUnit framework
How to Set Up JUnit
How to run a simple JUnit program
JUnit Annotations and Assert statements
Exceptions
Parameterized test
JUnit vs TestNG
www.edureka.co
www.edureka.co
JUnit is a testing
framework for Java
programming language.
It is important for test-
driven development.
Test first, code later
Unit Testing is used to
verify a small chunk of
code by creating a path,
function or a method.
www.edureka.co
01
02
03
04
05
06
07
JUnit provides a text-based command line
It also provides an AWT and Swing-based graphical test reporting mechanism
The best testing frameworks that can be selected for an efficient testing process
More Application Developer IDEs includes JUnit
JUnitEE test framework that enables it to test within the application server’s container
Widely adopted by many organizations around the world
A benchmark for testing in Java programming language
www.edureka.co
www.edureka.co
JUNIT
It allows you to write
codes faster, which
increases quality
It is elegantly
simple. It is less
complex
Provides annotations
to identify test
methods
It provides test
runners for
running the tests
Tests can be run
automatically
Tests can be organized
into test suites
www.edureka.co
www.edureka.co
JUnit is a Regression Testing framework which is used to
implement unit testing in Java. This framework also allows quick
and easy generation of test data and test cases.
Test fixtures
Test suites
Test runners
JUnit classes
www.edureka.co
Test fixtures
Test suites
Test runners
JUnit classes
Text fixtures ensures that there is a well-known and fixed environment in which
tests are run so that results are repeatable.
➢ setUp()
➢ tearDown()
www.edureka.co
Test fixtures
Test suites
Test runners
JUnit classes
www.edureka.co
If you want to execute multiple test cases in a specific order, it can be done by
combining all the test cases in a single origin. This origin is called the test suites.
➢ @Runwith
➢ @SuiteClasses
Test fixtures
Test suites
Test runners
JUnit classes
www.edureka.co
The test runner is used for executing the test cases.
➢ JUnitCore class is used in order to execute the tests.
➢ runClasses method is used to run one or several test cases.
➢ The return type of this method is the result object that is used to
access information about the tests.
Test fixtures
Test suites
Test runners
JUnit classes
www.edureka.co
JUnit classes are used in writing and testing JUnits.
➢ Assert
➢ TestCase
➢ TestResult
www.edureka.co
www.edureka.co
➢ Go to the Java Downloads Page and click on the option for Java Platform (JDK).
What is JUnit? | Edureka
www.edureka.co
What is JUnit? | Edureka
JUnit Annotations and Assert statements
www.edureka.co
JUnit Annotations and Assert statements
www.edureka.co
An annotation is a special form of
syntactic metadata that can be
added to the java source code for
better code readability
JUnit Annotations and Assert statements
www.edureka.co
Assert is a method used in
determining pass or fail
status of a test case. In
JUnit, all the assertions are
in the Assert class.
www.edureka.co
Exceptions
www.edureka.co
You can test whether the code throws the desired exception. The
expected parameter is used along with @Test annotation.
www.edureka.co
Create an instance variable
Create test cases using these
instance variables
Create a public constructor
Create @Parameters that returns a
Collection of Objects
Annotate test class with @RunWith
Parameterized test
What is JUnit? | Edureka
www.edureka.co
TestNG
Junit
Suite test
Annotation support
Ignore test
Execution
Dependency test
Parameterized test
@ignore @Test(enable=false)
@Before, @After
@RunWith and
@Parameter
@DataProvider
vs
www.edureka.co

More Related Content

What's hot (20)

PPTX
Unit tests & TDD
Dror Helper
 
PPTX
JUnit- A Unit Testing Framework
Onkar Deshpande
 
PPTX
Unit testing
Slideshare
 
PPTX
Unit Testing And Mocking
Joe Wilson
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PPTX
Test Automation Framework with BDD and Cucumber
Rhoynar Software Consulting
 
PDF
Unit testing best practices
nickokiss
 
PPS
Unit Testing
Anuj Arora
 
PPT
05 junit
mha4
 
PDF
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 
PPT
Manual testing concepts course 1
Raghu Kiran
 
PPTX
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
Software Testing Solution
 
PDF
Testing with Spring: An Introduction
Sam Brannen
 
PPTX
Software testing
Madhumita Chatterjee
 
PPTX
TestNG Framework
Levon Apreyan
 
PPTX
Bug life cycle
BugRaptors
 
PPTX
Unit Testing
Sergey Podolsky
 
PDF
BDD & Cucumber
Vladimir Arutin
 
PPTX
Katalon Studio Presentation.pptx
MuhammadHassan440279
 
PPTX
Unit Testing (C#)
Prashant Cholachagudd
 
Unit tests & TDD
Dror Helper
 
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Unit testing
Slideshare
 
Unit Testing And Mocking
Joe Wilson
 
Unit Testing Concepts and Best Practices
Derek Smith
 
Test Automation Framework with BDD and Cucumber
Rhoynar Software Consulting
 
Unit testing best practices
nickokiss
 
Unit Testing
Anuj Arora
 
05 junit
mha4
 
Interview Question & Answers for Selenium Freshers | LearningSlot
Learning Slot
 
Manual testing concepts course 1
Raghu Kiran
 
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
Software Testing Solution
 
Testing with Spring: An Introduction
Sam Brannen
 
Software testing
Madhumita Chatterjee
 
TestNG Framework
Levon Apreyan
 
Bug life cycle
BugRaptors
 
Unit Testing
Sergey Podolsky
 
BDD & Cucumber
Vladimir Arutin
 
Katalon Studio Presentation.pptx
MuhammadHassan440279
 
Unit Testing (C#)
Prashant Cholachagudd
 

Similar to What is JUnit? | Edureka (20)

PDF
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
PDF
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
PDF
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
PPTX
Unit testing by Svetlin Nakov
it-tour
 
PPTX
Unit Testing - Nakov's Talk @ VarnaConf 2013
Svetlin Nakov
 
PDF
Unit testing with Junit
Valerio Maggio
 
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
PulibandlaPraharshit
 
DOCX
JUnit_Guide_Expanded_Presentation[1].docx............................
PulibandlaPraharshit
 
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
PulibandlaPraharshit
 
PPT
Junit Interview Questions-ppt
Mayank Kumar
 
PPTX
Testing with Junit4
Amila Paranawithana
 
PDF
JUnit with_mocking
Zeeshan Khan
 
PPS
J unit presentation
Priya Sharma
 
PDF
Junit tutorial
Main Uddin Patowary
 
PDF
Java junit tutorial
Ashoka Vanjare
 
PDF
JUnit is a Regression Testing Framework used by developers to implem.pdf
aplolomedicalstoremr
 
PPTX
Junit4&testng presentation
Sanjib Dhar
 
PPT
3 j unit
kishoregali
 
PPTX
Unit Testing in Java
Ahmed M. Gomaa
 
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
Unit testing by Svetlin Nakov
it-tour
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Svetlin Nakov
 
Unit testing with Junit
Valerio Maggio
 
JUnit_Guide_Expanded_Presentation[1].docx
PulibandlaPraharshit
 
JUnit_Guide_Expanded_Presentation[1].docx............................
PulibandlaPraharshit
 
JUnit_Guide_Expanded_Presentation[1].docx
PulibandlaPraharshit
 
Junit Interview Questions-ppt
Mayank Kumar
 
Testing with Junit4
Amila Paranawithana
 
JUnit with_mocking
Zeeshan Khan
 
J unit presentation
Priya Sharma
 
Junit tutorial
Main Uddin Patowary
 
Java junit tutorial
Ashoka Vanjare
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
aplolomedicalstoremr
 
Junit4&testng presentation
Sanjib Dhar
 
3 j unit
kishoregali
 
Unit Testing in Java
Ahmed M. Gomaa
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 

What is JUnit? | Edureka

  • 2. What is JUnit? Advantages and uses Features The JUnit framework How to Set Up JUnit How to run a simple JUnit program JUnit Annotations and Assert statements Exceptions Parameterized test JUnit vs TestNG www.edureka.co
  • 4. JUnit is a testing framework for Java programming language. It is important for test- driven development. Test first, code later Unit Testing is used to verify a small chunk of code by creating a path, function or a method. www.edureka.co
  • 5. 01 02 03 04 05 06 07 JUnit provides a text-based command line It also provides an AWT and Swing-based graphical test reporting mechanism The best testing frameworks that can be selected for an efficient testing process More Application Developer IDEs includes JUnit JUnitEE test framework that enables it to test within the application server’s container Widely adopted by many organizations around the world A benchmark for testing in Java programming language www.edureka.co
  • 7. JUNIT It allows you to write codes faster, which increases quality It is elegantly simple. It is less complex Provides annotations to identify test methods It provides test runners for running the tests Tests can be run automatically Tests can be organized into test suites www.edureka.co
  • 9. JUnit is a Regression Testing framework which is used to implement unit testing in Java. This framework also allows quick and easy generation of test data and test cases. Test fixtures Test suites Test runners JUnit classes www.edureka.co
  • 10. Test fixtures Test suites Test runners JUnit classes Text fixtures ensures that there is a well-known and fixed environment in which tests are run so that results are repeatable. ➢ setUp() ➢ tearDown() www.edureka.co
  • 11. Test fixtures Test suites Test runners JUnit classes www.edureka.co If you want to execute multiple test cases in a specific order, it can be done by combining all the test cases in a single origin. This origin is called the test suites. ➢ @Runwith ➢ @SuiteClasses
  • 12. Test fixtures Test suites Test runners JUnit classes www.edureka.co The test runner is used for executing the test cases. ➢ JUnitCore class is used in order to execute the tests. ➢ runClasses method is used to run one or several test cases. ➢ The return type of this method is the result object that is used to access information about the tests.
  • 13. Test fixtures Test suites Test runners JUnit classes www.edureka.co JUnit classes are used in writing and testing JUnits. ➢ Assert ➢ TestCase ➢ TestResult
  • 15. www.edureka.co ➢ Go to the Java Downloads Page and click on the option for Java Platform (JDK).
  • 19. JUnit Annotations and Assert statements www.edureka.co
  • 20. JUnit Annotations and Assert statements www.edureka.co An annotation is a special form of syntactic metadata that can be added to the java source code for better code readability
  • 21. JUnit Annotations and Assert statements www.edureka.co Assert is a method used in determining pass or fail status of a test case. In JUnit, all the assertions are in the Assert class.
  • 23. Exceptions www.edureka.co You can test whether the code throws the desired exception. The expected parameter is used along with @Test annotation.
  • 25. Create an instance variable Create test cases using these instance variables Create a public constructor Create @Parameters that returns a Collection of Objects Annotate test class with @RunWith Parameterized test
  • 28. TestNG Junit Suite test Annotation support Ignore test Execution Dependency test Parameterized test @ignore @Test(enable=false) @Before, @After @RunWith and @Parameter @DataProvider vs