SlideShare a Scribd company logo
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!

More Related Content

What's hot

Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
Francesco Garavaglia
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
12 functional-system-testing
12 functional-system-testing12 functional-system-testing
12 functional-system-testingnickynicks76
 
Unit test
Unit testUnit test
Unit test
Tran Duc
 
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...
Thomas Weller
 
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 2012Jacinto Limjap
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
Marius Crisan
 
System testing
System testingSystem testing
System testing
Bernie Fishpool
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
GomathiNayagam S
 
Ch8-Software Engineering 9
Ch8-Software Engineering 9Ch8-Software Engineering 9
Ch8-Software Engineering 9Ian Sommerville
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Scott Leberknight
 
Software testing
Software testingSoftware testing
Software testingBala Ganesh
 
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.
Deepak Singhvi
 
Types of Software Testing
Types of Software TestingTypes of Software Testing
Types of Software TestingNishant Worah
 
Moq presentation
Moq presentationMoq presentation
Moq presentationLynxStar
 
Thetheoryofsoftwaretesting
ThetheoryofsoftwaretestingThetheoryofsoftwaretesting
Thetheoryofsoftwaretesting
PiyushMehta57
 

What's hot (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
 

Similar to Unit testing and 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 p
20EC040
 
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
 
Unit test Android
Unit test AndroidUnit test Android
Unit test Android
Qushay Bagas
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnit
Mindfire Solutions
 
Software testing
Software testingSoftware testing
Software testing
Aman Adhikari
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
Ahmed M. Gomaa
 
JUnit with_mocking
JUnit with_mockingJUnit with_mocking
JUnit with_mocking
Zeeshan Khan
 
ST Unit-3.pptx
ST Unit-3.pptxST Unit-3.pptx
ST Unit-3.pptx
JhonLiver
 
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.docx
8759000398
 
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 assignment
Muhammad Arshad
 
Junit Interview Questions-ppt
Junit Interview Questions-pptJunit Interview Questions-ppt
Junit Interview Questions-ppt
Mayank Kumar
 
Software enginnenring Book Slides By summer
Software enginnenring Book Slides By summerSoftware enginnenring Book Slides By summer
Software enginnenring Book Slides By summer
p229279
 
Ch8.testing
Ch8.testingCh8.testing
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
AMITJain879
 
Ch8 - Testing
Ch8 - TestingCh8 - Testing
Ch8 - Testing
Harsh Verdhan Raj
 

Similar to Unit testing and 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
 
Software enginnenring Book Slides By summer
Software enginnenring Book Slides By summerSoftware enginnenring Book Slides By summer
Software enginnenring Book Slides By summer
 
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
Ch8 - TestingCh8 - Testing
Ch8 - Testing
 

More from Ömer Taşkın

GraphDB
GraphDBGraphDB
No sql and mongodb
No sql and mongodbNo sql and mongodb
No sql and mongodb
Ömer Taşkın
 
Dependency management
Dependency managementDependency management
Dependency management
Ömer Taşkın
 
Orm
OrmOrm
Soa
SoaSoa
Oop basics
Oop basicsOop basics
Oop basics
Ömer Taşkın
 
Web Programming - Git basics
Web Programming - Git basicsWeb Programming - Git basics
Web Programming - Git basics
Ömer Taşkın
 
Php101
Php101Php101
XXLWEB
XXLWEBXXLWEB

More from Ö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
 

Recently uploaded

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

Unit testing and 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