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

PDF
PPS
JUnit Presentation
PPTX
Unit Testing Concepts and Best Practices
PPTX
Unit Testing And Mocking
PPTX
Introduction to JUnit
PPSX
PPT
05 junit
PDF
JUnit & Mockito, first steps
JUnit Presentation
Unit Testing Concepts and Best Practices
Unit Testing And Mocking
Introduction to JUnit
05 junit
JUnit & Mockito, first steps

What's hot (20)

PPTX
Automation Testing by Selenium Web Driver
PPTX
Unit Testing in Java
PDF
An introduction to unit testing
PPTX
Unit tests & TDD
PPTX
Unit Testing
PDF
Unit and integration Testing
PPT
Selenium
PDF
Create an architecture for web test automation
PPTX
An Introduction to Unit Testing
PPTX
TestNG Framework
PDF
Unit testing with JUnit
PPTX
Test-Driven Development
PDF
Introduction to Robot Framework
PPTX
Introduction to Bdd and cucumber
PPTX
Selenium WebDriver training
PPS
Unit Testing
PPTX
Robot Framework
PPT
PPTX
Test NG Framework Complete Walk Through
Automation Testing by Selenium Web Driver
Unit Testing in Java
An introduction to unit testing
Unit tests & TDD
Unit Testing
Unit and integration Testing
Selenium
Create an architecture for web test automation
An Introduction to Unit Testing
TestNG Framework
Unit testing with JUnit
Test-Driven Development
Introduction to Robot Framework
Introduction to Bdd and cucumber
Selenium WebDriver training
Unit Testing
Robot Framework
Test NG Framework Complete Walk Through
Ad

Similar to What is JUnit? | Edureka (20)

PDF
junit-160729073220 eclipse software testing.pdf
PDF
JUnit Testing Framework A Complete Guide.pdf
PDF
JUnit Testing Framework A Complete Guide.pdf
PPTX
Unit testing by Svetlin Nakov
PPTX
Unit Testing - Nakov's Talk @ VarnaConf 2013
PDF
Unit testing with Junit
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
DOCX
JUnit_Guide_Expanded_Presentation[1].docx............................
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
PPT
PPTX
JUnit- A Unit Testing Framework
PPT
Junit Interview Questions-ppt
PPTX
Testing with Junit4
PDF
JUnit with_mocking
PPS
J unit presentation
PDF
Junit tutorial
PDF
Java junit tutorial
PDF
JUnit is a Regression Testing Framework used by developers to implem.pdf
PPTX
Junit4&testng presentation
junit-160729073220 eclipse software testing.pdf
JUnit Testing Framework A Complete Guide.pdf
JUnit Testing Framework A Complete Guide.pdf
Unit testing by Svetlin Nakov
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit testing with Junit
JUnit_Guide_Expanded_Presentation[1].docx
JUnit_Guide_Expanded_Presentation[1].docx............................
JUnit_Guide_Expanded_Presentation[1].docx
JUnit- A Unit Testing Framework
Junit Interview Questions-ppt
Testing with Junit4
JUnit with_mocking
J unit presentation
Junit tutorial
Java junit tutorial
JUnit is a Regression Testing Framework used by developers to implem.pdf
Junit4&testng presentation
Ad

More from Edureka! (20)

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

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Encapsulation theory and applications.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Modernizing your data center with Dell and AMD
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

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