SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Ravi Kant Soni
Senior Software Engineer
i-Admin , Bangalore
i-Admin,Bangalore
1
WHAT IS TESTING
Testing is the process of checking the
functionality of the application whether it
is working as per requirements
2
i-Admin,Bangalore
WHAT IS JUNIT
DeFacto framework for developing unit
test in java
 Currently version 4.x
Developed by Erich Gamma & Kent Beck
Released under IBM, and hosted on
sourcefog
Promotes the idea of "first testing then
coding“ 3
i-Admin,Bangalore
FEATURES OF JUNIT
An open source framework which is used
for writing & running tests
Shows test progress in a bar that is green
if test is going fine and it turns red when a
test fails
Provides Annotation & Assertions
4
i-Admin,Bangalore
WHAT IS UNIT TEST CASES?
Unit testing is the testing of single entity
(class or method)
A Unit Test Case is a part of code which
ensures that the another part of code
(method) works as expected
There must be at least two test cases for
each requirement: one positive test and
one negative test 5
i-Admin,Bangalore
JUNIT ENVIRONMENT SETUP
JUnit is a framework for Java, so the very
first requirement is to have JDK installed
in your machine.
Download latest version of JUnit jar file
from http://www.junit.org.
6
i-Admin,Bangalore
SET ECLIPSE ENVIRONMENT
7
i-Admin,Bangalore
JUNIT 4
8
i-Admin,Bangalore
Automatically recognizes test methods
preceded by @Test annotation
No need for main() to run the tests
Test methods must be public, void, with
no parameters
EXAMPLE
import org.junit.Test; // for @Test
import static org.junit.Assert.assertEquals; // assertEquals()
public class TestJunit {
@Test
public void testAdd() {
assertEquals(2, 2 + 1);
}
}
9
i-Admin,Bangalore
JUNIT TEST OUTPUT
10
i-Admin,Bangalore
JUNIT TEST OUTPUT
11
i-Admin,Bangalore
JUNIT TEST OUTPUT
12
i-Admin,Bangalore
Runs
Total number of tests run
Failures
Tests that failed. For example assertions that
failed.
Errors
Tests that generated unhandled (unexpected)
exceptions.
Time elapsed (ms)
JUNIT CLASSES
JUnit classes are important classes which is
used in writing and testing Junits
Assert which contain a set of assert
methods
TestCase which contain a test case defines
the fixture to run multiple tests
13
i-Admin,Bangalore
ASSERT
org.junit.Assert.* static methods:
 void assertEquals(expected, actual)
 Works with object, int, long, byte, string, etc
 Object: it invokes object.equals(object) for equality
 assertEquals (expected, actual, εpsilon)
 float and double
 void assertFalse/ True(boolean condition)
 void assertNull/ NotNull(Object object)
 void fail() 14
i-Admin,Bangalore
ASSERT EXAMPLE
i-Admin,Bangalore
15
ANNOTATION
Annotations are like meta-tags
 @Test
 @Before
 @After
 @BeforeClass
 @AfterClass
 @Ignore
16
i-Admin,Bangalore
ANNOTATION EXAMPLE
i-Admin,Bangalore
17
PARAMETERIZED TEST
 Allows you to run the same test with different
data
 @RunWith(Parameterized.class)
 public static method that returns a Collection
of data
 Collection must be an Array of the various
parameters used for the test
 public constructor that uses the parameters 18
i-Admin,Bangalore
PARAMETERIZED EXAMPLE
i-Admin,Bangalore
19
SUITES
 Specify an execution order
 Add @Suite to an empty class
@RunWith(Suite.class)
@Suite.SuiteClasses({SomeTest.class})
public class AllTests { }
20
i-Admin,Bangalore
SUITES EXAMPLE
i-Admin,Bangalore
21
TESTING EXCEPTIONS
i-Admin,Bangalore
22
GOOD UNIT TEST
 Any static utility method must have test
 Make exception tests
 Business models with equals and hashcode
 Test that “something is true” but also that
“not-something is false”
 Give your tests meaningful names
23
i-Admin,Bangalore
MORE RESOURCE
 Official site: www.junit.org
 JUnit cook book
http://junit.sourceforge.net/doc/cookbook
/cookbook.htm (one recipe long!)
 JUnit Javadoc:
http://junit.org/junit/javadoc/4.5/
24
i-Admin,Bangalore
i-Admin,Bangalore
25

Más contenido relacionado

La actualidad más candente

Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
Sayedur Rahman
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
Joe Wilson
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
Dror Helper
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 

La actualidad más candente (18)

An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
 
White box testing
White box testing White box testing
White box testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 

Destacado

Диплом Никифорова А.
Диплом Никифорова А.Диплом Никифорова А.
Диплом Никифорова А.
Socreklamanalytics
 
Курсовая Сланова Н.
Курсовая Сланова Н.Курсовая Сланова Н.
Курсовая Сланова Н.
Socreklamanalytics
 
портфоліо на мк 2013 [автосохраненный] готовий
портфоліо  на мк 2013 [автосохраненный] готовийпортфоліо  на мк 2013 [автосохраненный] готовий
портфоліо на мк 2013 [автосохраненный] готовий
les1812
 
Курсовая Хананушан Н.
Курсовая Хананушан Н.Курсовая Хананушан Н.
Курсовая Хананушан Н.
Socreklamanalytics
 
Pragati a4 brouchre - wide
Pragati   a4 brouchre - widePragati   a4 brouchre - wide
Pragati a4 brouchre - wide
sujiswetha65
 
Диплом Пакалина Ю.
Диплом Пакалина Ю.Диплом Пакалина Ю.
Диплом Пакалина Ю.
Socreklamanalytics
 

Destacado (17)

Диплом Никифорова А.
Диплом Никифорова А.Диплом Никифорова А.
Диплом Никифорова А.
 
Religion
ReligionReligion
Religion
 
Oktaviani sari
Oktaviani sariOktaviani sari
Oktaviani sari
 
Zed ria presentation
Zed ria presentationZed ria presentation
Zed ria presentation
 
Gui automation framework
Gui automation frameworkGui automation framework
Gui automation framework
 
Matilla Portfolio
Matilla PortfolioMatilla Portfolio
Matilla Portfolio
 
Курсовая Сланова Н.
Курсовая Сланова Н.Курсовая Сланова Н.
Курсовая Сланова Н.
 
Data driven decision-making - Students' Unions 2013
Data driven decision-making - Students' Unions 2013Data driven decision-making - Students' Unions 2013
Data driven decision-making - Students' Unions 2013
 
Padur flower presentation sujitha
Padur   flower presentation sujithaPadur   flower presentation sujitha
Padur flower presentation sujitha
 
портфоліо на мк 2013 [автосохраненный] готовий
портфоліо  на мк 2013 [автосохраненный] готовийпортфоліо  на мк 2013 [автосохраненный] готовий
портфоліо на мк 2013 [автосохраненный] готовий
 
Курсовая Хананушан Н.
Курсовая Хананушан Н.Курсовая Хананушан Н.
Курсовая Хананушан Н.
 
Совершенствование методов фестивальной оценки рекламной деятельности (на при...
Совершенствование методов фестивальной оценки рекламной деятельности  (на при...Совершенствование методов фестивальной оценки рекламной деятельности  (на при...
Совершенствование методов фестивальной оценки рекламной деятельности (на при...
 
Pragati a4 brouchre - wide
Pragati   a4 brouchre - widePragati   a4 brouchre - wide
Pragati a4 brouchre - wide
 
Pp pidato
Pp pidatoPp pidato
Pp pidato
 
Pp pidato
Pp pidatoPp pidato
Pp pidato
 
Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)Spring MVC 3.0 Framework (sesson_2)
Spring MVC 3.0 Framework (sesson_2)
 
Диплом Пакалина Ю.
Диплом Пакалина Ю.Диплом Пакалина Ю.
Диплом Пакалина Ю.
 

Similar a Junit

Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
Software Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By SrikanthSoftware Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By Srikanth
Srikanth Krishnamoorthy
 

Similar a Junit (20)

SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
 
Junit Interview Questions-ppt
Junit Interview Questions-pptJunit Interview Questions-ppt
Junit Interview Questions-ppt
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 
Testing on frontend
Testing on frontendTesting on frontend
Testing on frontend
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnit
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
Google test training
Google test trainingGoogle test training
Google test training
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Unit testing and junit
Unit testing and junitUnit testing and junit
Unit testing and junit
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Software Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By SrikanthSoftware Testing - A sneak preview By Srikanth
Software Testing - A sneak preview By Srikanth
 

Último

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Junit