SlideShare une entreprise Scribd logo
1  sur  19
eleks.comeleks.com
Unit & Integration Testing
A way to a better software
Introduction
The main work is
performed in
implementation &
testing phases.
Unit tests save time &
improve design.
What is a unit test?
A unit test is a piece of a code (usually a method) that
invokes another piece of code and checks the correctness
of some assumptions afterward.
If the assumptions turn out to be wrong, the unit test has
failed. A unit is a method or function.
What a unit test should not do?
Unit tests are not about finding bugs, they’re all about code
verification.
Unit tests are not supposed to be built on top of existing
design for the sake of code coverage.
In fact, they should drive your system towards flexible &
testable design, thus providing an interface to verify the
correctness of the input/output of the unit.
Unit tests scope
The scope of Unit testing is narrow, it covers the
Unit or small piece of code under test.
Therefore while writing a unit test shorter codes
are used that target just a single class.
Unit tests should have no dependencies on
code outside the unit tested.
What exactly should be tested?
- Tests should be written for a specific CUT
- Tests should cover only the API of this CUT and are not
supposed to test the implementation details of a unit
- Test only units with some logic (e.g. methods and
functions not properties)
- It makes sense to test only those units over which you
have control
- Test CUTs against interfaces
Single Responsibility
Test behaviour, not methods:
- One method, multiple behaviours -> Multiple Tests
- One behaviour, multiple methods -> One Test
- A method calls private & protected methods
- A method calls properties
- One behaviour, one result -> One Assert
- Multiple asserts are okay as long as they check the
same behaviour
What makes a good unit test?
A good unit test should have the following properties:
- It should be automated and repeatable.
- It should be easy to implement.
- It should be relevant tomorrow.
- Anyone should be able to run it at the push of a button.
- It should run quickly.
- It should be consistent in its results.
- It should have full control of the unit under test.
What makes a good unit test?
A good unit test should have the following properties:
- It should be fully isolated from other tests.
- When it fails, it should be easy to detect what was
expected and determine how to pinpoint the problem.
- Fails when the logic against which it was tested changes
- Doesn’t make you want to comment them
- Doesn’t call other tests
- Are implemented quickly
- Covers multiple behaviours
How to verify that test is correct?
After implementing a test try changing the
behaviour of the unit, so it down not meet the
requirement anymore, and run it again. It should
fail.
Failing tests are as important as passing ones.
What is an integration test?
Integration testing is testing a unit of work
without having full control over all of it and using
one or more of its real dependencies, such as
time, network, database, threads, random
number generators, and so on.
Integration tests scope
The scope of Integration testing is wide, it
covers the whole application under test and it
requires much more effort to put together.
Integration testing is dependent on other
outside systems like databases, hardware
allocated for them etc.
Benefits of unit & integration tests
- Helps to improve and
build flexible design
- Verifies that code is
working as intended
- Helps to stick to
requirements
- Is a good source for
code documentation
- Unit tests are a form of
sample code
- Detect failing logic
upfront
- Measures the
completion of a class
- Pinpoints the problem
location
- Simplifies integration
Test structure patterns
A A AArrange
(Given)
Assert
(Then)
Act
(When)
Naming convention
UnitOfWork_StateUnderTest_ExpectedBehavior()
1. Unit of work - name of method you are testing
2. State under test - short name for the state/input used for current test
3. Expected behavior - short name for expected result of the test which
you’re going to check
Test Driven Development
Many people feel that the best time to write unit
tests for software is after the software has been
written, but a growing number prefer writing unit
tests before the production code is written. This
approach is called test-first or test-driven
development (TDD).
Red - Green -
Refactor
Write a failing test to prove code or
functionality is missing from the end
product.
Make the test pass by writing
production code that meets the
expectations of your test.
Refactor your code.
Additional resources
The Art of Unit Testing: with Examples in C#, Second Edition
by Roy Osherove
Writing Great Unit Tests: Best and Worst Practices:
http://blog.stevensanderson.com/2009/08/24/writing-great-
unit-tests-best-and-worst-practises/
eleks.com
Inspired by Technology.
Driven by Value.

Contenu connexe

Tendances (20)

Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 
TestNG
TestNGTestNG
TestNG
 
Test Automation
Test AutomationTest Automation
Test Automation
 
What is Integration Testing? | Edureka
What is Integration Testing? | EdurekaWhat is Integration Testing? | Edureka
What is Integration Testing? | Edureka
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
테스트자동화와 TDD
테스트자동화와 TDD테스트자동화와 TDD
테스트자동화와 TDD
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Unit test
Unit testUnit test
Unit test
 
Junit
JunitJunit
Junit
 
Test automation
Test automationTest automation
Test automation
 
Test automation methodologies
Test automation methodologiesTest automation methodologies
Test automation methodologies
 
Istqb foundation level day 1
Istqb foundation level   day 1Istqb foundation level   day 1
Istqb foundation level day 1
 
Types of testing
Types of testingTypes of testing
Types of testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Test ng
Test ngTest ng
Test ng
 
ISTQB Foundation Level Basic
ISTQB Foundation Level BasicISTQB Foundation Level Basic
ISTQB Foundation Level Basic
 

Similaire à Unit & integration testing

Software Testing Strategies ,Validation Testing and System Testing.
Software Testing Strategies ,Validation Testing and System Testing.Software Testing Strategies ,Validation Testing and System Testing.
Software Testing Strategies ,Validation Testing and System Testing.Tanzeem Aslam
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsMarcelo Busico
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented TestingAMITJain879
 
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
 
Test Process
Test ProcessTest Process
Test Processtokarthik
 
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
 
Software testing part
Software testing partSoftware testing part
Software testing partPreeti Mishra
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4 Mohammad Faizan
 
Testing in Software Engineering.docx
Testing in Software Engineering.docxTesting in Software Engineering.docx
Testing in Software Engineering.docx8759000398
 

Similaire à Unit & integration testing (20)

Testing
TestingTesting
Testing
 
Software Testing Strategies ,Validation Testing and System Testing.
Software Testing Strategies ,Validation Testing and System Testing.Software Testing Strategies ,Validation Testing and System Testing.
Software Testing Strategies ,Validation Testing and System Testing.
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
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.
 
Software testing
Software testingSoftware testing
Software testing
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test Process
Test ProcessTest Process
Test Process
 
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.
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
Testing
Testing Testing
Testing
 
Software testing part
Software testing partSoftware testing part
Software testing part
 
SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4  SOFTWARE TESTING UNIT-4
SOFTWARE TESTING UNIT-4
 
Software unit4
Software unit4Software unit4
Software unit4
 
Testing in Software Engineering.docx
Testing in Software Engineering.docxTesting in Software Engineering.docx
Testing in Software Engineering.docx
 

Dernier

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 

Dernier (20)

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 

Unit & integration testing

  • 1. eleks.comeleks.com Unit & Integration Testing A way to a better software
  • 2. Introduction The main work is performed in implementation & testing phases. Unit tests save time & improve design.
  • 3. What is a unit test? A unit test is a piece of a code (usually a method) that invokes another piece of code and checks the correctness of some assumptions afterward. If the assumptions turn out to be wrong, the unit test has failed. A unit is a method or function.
  • 4. What a unit test should not do? Unit tests are not about finding bugs, they’re all about code verification. Unit tests are not supposed to be built on top of existing design for the sake of code coverage. In fact, they should drive your system towards flexible & testable design, thus providing an interface to verify the correctness of the input/output of the unit.
  • 5. Unit tests scope The scope of Unit testing is narrow, it covers the Unit or small piece of code under test. Therefore while writing a unit test shorter codes are used that target just a single class. Unit tests should have no dependencies on code outside the unit tested.
  • 6. What exactly should be tested? - Tests should be written for a specific CUT - Tests should cover only the API of this CUT and are not supposed to test the implementation details of a unit - Test only units with some logic (e.g. methods and functions not properties) - It makes sense to test only those units over which you have control - Test CUTs against interfaces
  • 7. Single Responsibility Test behaviour, not methods: - One method, multiple behaviours -> Multiple Tests - One behaviour, multiple methods -> One Test - A method calls private & protected methods - A method calls properties - One behaviour, one result -> One Assert - Multiple asserts are okay as long as they check the same behaviour
  • 8. What makes a good unit test? A good unit test should have the following properties: - It should be automated and repeatable. - It should be easy to implement. - It should be relevant tomorrow. - Anyone should be able to run it at the push of a button. - It should run quickly. - It should be consistent in its results. - It should have full control of the unit under test.
  • 9. What makes a good unit test? A good unit test should have the following properties: - It should be fully isolated from other tests. - When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem. - Fails when the logic against which it was tested changes - Doesn’t make you want to comment them - Doesn’t call other tests - Are implemented quickly - Covers multiple behaviours
  • 10. How to verify that test is correct? After implementing a test try changing the behaviour of the unit, so it down not meet the requirement anymore, and run it again. It should fail. Failing tests are as important as passing ones.
  • 11. What is an integration test? Integration testing is testing a unit of work without having full control over all of it and using one or more of its real dependencies, such as time, network, database, threads, random number generators, and so on.
  • 12. Integration tests scope The scope of Integration testing is wide, it covers the whole application under test and it requires much more effort to put together. Integration testing is dependent on other outside systems like databases, hardware allocated for them etc.
  • 13. Benefits of unit & integration tests - Helps to improve and build flexible design - Verifies that code is working as intended - Helps to stick to requirements - Is a good source for code documentation - Unit tests are a form of sample code - Detect failing logic upfront - Measures the completion of a class - Pinpoints the problem location - Simplifies integration
  • 14. Test structure patterns A A AArrange (Given) Assert (Then) Act (When)
  • 15. Naming convention UnitOfWork_StateUnderTest_ExpectedBehavior() 1. Unit of work - name of method you are testing 2. State under test - short name for the state/input used for current test 3. Expected behavior - short name for expected result of the test which you’re going to check
  • 16. Test Driven Development Many people feel that the best time to write unit tests for software is after the software has been written, but a growing number prefer writing unit tests before the production code is written. This approach is called test-first or test-driven development (TDD).
  • 17. Red - Green - Refactor Write a failing test to prove code or functionality is missing from the end product. Make the test pass by writing production code that meets the expectations of your test. Refactor your code.
  • 18. Additional resources The Art of Unit Testing: with Examples in C#, Second Edition by Roy Osherove Writing Great Unit Tests: Best and Worst Practices: http://blog.stevensanderson.com/2009/08/24/writing-great- unit-tests-best-and-worst-practises/