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)

PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Digital Circuits, important subject in CS
contactparinay1
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 

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