SlideShare ist ein Scribd-Unternehmen logo
1 von 22
INTERNET
PROGRAMMING II
Yildiz Technical University 2015
Ömer Taşkın
Unit Testing & Junit
OUTLINE
•What is Software Testing
•Types
•Unit Testing
•Integration Testing
•JUnit
•Mocking
What is Software Testing
Part of the software development life cycle
What is Software Testing
• Points out the defects and errors that were made during the development
phases
• Ensures the Quality of product
• Requires lower maintenance cost
Software Testing Levels
Functional Testing
Unit Testing
Integration Testing
Security Testing
Acceptance Testing
Alpha Testing
Beta Testing
etc…
Unit Testing
A unit is the smallest testable part of an application like functions, classes,
procedures, interfaces.
Unit testing is a method by which individual units of source code are
tested to determine if they are fit for use.
Unit testing should be done before Integration testing.
Unit testing simplifies the debugging process.
Integration Testing
Integration testing is Unit Testing ++
Integration Testing is integrated with Databases, File System, Hardware
etc.
Unit Test versus Integration Test
Unit test verifies the logic of small piece of code
Unit tests shouldn't have dependencies on outside systems
Integration test is done to demonstrate that different pieces of the system work
together.
Integration tests cover whole applications
JUnit
Unit & Integration testing framework @ Java
JUnit
Unit & Integration testing framework @ Java
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
Can be used on maven
JUnit
Requires @Test annotation to be testable method
Return type of methods have to be void
@Test
public void sampleTestMethod() {
//
}
JUnit Assertions
Assert can check value is null empty true false equals to given etc.
assertEquals();
assertTrue();
assertFalse();
assertNotNull();
assertNull();
JUnit Assertions
Assert can check value is null empty true false equals to given etc.
@Test
public void testMethod() {
Integer multipliedNums = multiply(1,3);
Assert.assertEquals(3, multipliedNums );
}
public Integer multiply(int first, int next) {
return x*y;
}
Test passed
Mocking
Mocking is keep dependencies out of unit tests
Mocking
real objects mocked objects
Mockito
Mockito is one of Mocking framework which used in Java
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
Can be used on maven
Mockito
@Mock creates mock object
@Mock
private CategoryDao categoryDao;
Mockito
@InjectMocks creates an instance of the class and injects the mocks that
are created with the @Mock
@InjectMocks
private CategoryController categoryController;
Mockito
when().then()
List<Category> categories = new ArrayList();
when(categoryDao.findAll()).thenReturn(categories);
when a method was called then simulate something
LET’S WORK TOGETHER!

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Ch23
Ch23Ch23
Ch23
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
12 functional-system-testing
12 functional-system-testing12 functional-system-testing
12 functional-system-testing
 
Unit test
Unit testUnit test
Unit test
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
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
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
 
System testing
System testingSystem testing
System testing
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Ch8-Software Engineering 9
Ch8-Software Engineering 9Ch8-Software Engineering 9
Ch8-Software Engineering 9
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software testing
Software testingSoftware testing
Software testing
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software Testing
 
Moq presentation
Moq presentationMoq presentation
Moq presentation
 
Thetheoryofsoftwaretesting
ThetheoryofsoftwaretestingThetheoryofsoftwaretesting
Thetheoryofsoftwaretesting
 

Ähnlich wie Unit Testing & JUnit

unit 4.pptx very needful and important p
unit 4.pptx very needful and important punit 4.pptx very needful and important p
unit 4.pptx very needful and important p20EC040
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Mohamed Taman
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitMindfire Solutions
 
JUnit with_mocking
JUnit with_mockingJUnit with_mocking
JUnit with_mockingZeeshan Khan
 
ST Unit-3.pptx
ST Unit-3.pptxST Unit-3.pptx
ST Unit-3.pptxJhonLiver
 
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_v2Tricode (part of Dept)
 
Testing in Software Engineering.docx
Testing in Software Engineering.docxTesting in Software Engineering.docx
Testing in Software Engineering.docx8759000398
 
Interview questions for manual testing technology.
Interview questions for manual testing technology.Interview questions for manual testing technology.
Interview questions for manual testing technology.Vinay Agnihotri
 
Software testing assignment
Software testing assignmentSoftware testing assignment
Software testing assignmentMuhammad Arshad
 
Junit Interview Questions-ppt
Junit Interview Questions-pptJunit Interview Questions-ppt
Junit Interview Questions-pptMayank Kumar
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented TestingAMITJain879
 

Ähnlich wie Unit Testing & JUnit (20)

unit 4.pptx very needful and important p
unit 4.pptx very needful and important punit 4.pptx very needful and important p
unit 4.pptx very needful and important p
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Unit test Android
Unit test AndroidUnit test Android
Unit test Android
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnit
 
Software testing
Software testingSoftware testing
Software testing
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
JUnit with_mocking
JUnit with_mockingJUnit with_mocking
JUnit with_mocking
 
ST Unit-3.pptx
ST Unit-3.pptxST Unit-3.pptx
ST Unit-3.pptx
 
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
 
Tdd dev session
Tdd dev sessionTdd dev session
Tdd dev session
 
Testing in Software Engineering.docx
Testing in Software Engineering.docxTesting in Software Engineering.docx
Testing in Software Engineering.docx
 
Interview questions for manual testing technology.
Interview questions for manual testing technology.Interview questions for manual testing technology.
Interview questions for manual testing technology.
 
Software testing assignment
Software testing assignmentSoftware testing assignment
Software testing assignment
 
Junit Interview Questions-ppt
Junit Interview Questions-pptJunit Interview Questions-ppt
Junit Interview Questions-ppt
 
Ch8.testing
Ch8.testingCh8.testing
Ch8.testing
 
Quality for developers
Quality for developersQuality for developers
Quality for developers
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
 
Ch8.Testing.pptx
Ch8.Testing.pptxCh8.Testing.pptx
Ch8.Testing.pptx
 
Ch8 - Testing
Ch8 - TestingCh8 - Testing
Ch8 - Testing
 

Mehr von Ömer Taşkın (9)

GraphDB
GraphDBGraphDB
GraphDB
 
No sql and mongodb
No sql and mongodbNo sql and mongodb
No sql and mongodb
 
Dependency management
Dependency managementDependency management
Dependency management
 
Orm
OrmOrm
Orm
 
Soa
SoaSoa
Soa
 
Oop basics
Oop basicsOop basics
Oop basics
 
Web Programming - Git basics
Web Programming - Git basicsWeb Programming - Git basics
Web Programming - Git basics
 
Php101
Php101Php101
Php101
 
XXLWEB
XXLWEBXXLWEB
XXLWEB
 

Kürzlich hochgeladen

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Kürzlich hochgeladen (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

Unit Testing & JUnit

  • 1. INTERNET PROGRAMMING II Yildiz Technical University 2015 Ömer Taşkın Unit Testing & Junit
  • 2. OUTLINE •What is Software Testing •Types •Unit Testing •Integration Testing •JUnit •Mocking
  • 3. What is Software Testing Part of the software development life cycle
  • 4. What is Software Testing • Points out the defects and errors that were made during the development phases • Ensures the Quality of product • Requires lower maintenance cost
  • 5.
  • 6. Software Testing Levels Functional Testing Unit Testing Integration Testing Security Testing Acceptance Testing Alpha Testing Beta Testing etc…
  • 7.
  • 8. Unit Testing A unit is the smallest testable part of an application like functions, classes, procedures, interfaces. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. Unit testing should be done before Integration testing. Unit testing simplifies the debugging process.
  • 9. Integration Testing Integration testing is Unit Testing ++ Integration Testing is integrated with Databases, File System, Hardware etc.
  • 10. Unit Test versus Integration Test Unit test verifies the logic of small piece of code Unit tests shouldn't have dependencies on outside systems Integration test is done to demonstrate that different pieces of the system work together. Integration tests cover whole applications
  • 11. JUnit Unit & Integration testing framework @ Java
  • 12. JUnit Unit & Integration testing framework @ Java <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> Can be used on maven
  • 13. JUnit Requires @Test annotation to be testable method Return type of methods have to be void @Test public void sampleTestMethod() { // }
  • 14. JUnit Assertions Assert can check value is null empty true false equals to given etc. assertEquals(); assertTrue(); assertFalse(); assertNotNull(); assertNull();
  • 15. JUnit Assertions Assert can check value is null empty true false equals to given etc. @Test public void testMethod() { Integer multipliedNums = multiply(1,3); Assert.assertEquals(3, multipliedNums ); } public Integer multiply(int first, int next) { return x*y; } Test passed
  • 16. Mocking Mocking is keep dependencies out of unit tests
  • 18. Mockito Mockito is one of Mocking framework which used in Java <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> </dependency> Can be used on maven
  • 19. Mockito @Mock creates mock object @Mock private CategoryDao categoryDao;
  • 20. Mockito @InjectMocks creates an instance of the class and injects the mocks that are created with the @Mock @InjectMocks private CategoryController categoryController;
  • 21. Mockito when().then() List<Category> categories = new ArrayList(); when(categoryDao.findAll()).thenReturn(categories); when a method was called then simulate something