SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
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.

More Related Content

What's hot (20)

PDF
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
PPTX
UNIT TESTING
Marius Crisan
 
PPTX
Understanding Unit Testing
ikhwanhayat
 
PPSX
Junit
FAROOK Samath
 
PPTX
functional testing
bharathanche
 
PPTX
UNIT TESTING PPT
suhasreddy1
 
PPT
Agile QA and Testing process
Gloria Stoilova
 
KEY
Arquitetura de Automação de Teste
Elias Nogueira
 
PDF
Selenium IDE LOCATORS
Mindfire Solutions
 
PPTX
The Test Pyramid
Thiago Ghisi
 
PDF
How to Automate API Testing
Bruno Pedro
 
PDF
Building a Test Automation Strategy for Success
Lee Barnes
 
PPTX
Unit tests & TDD
Dror Helper
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PDF
Static Code Analysis
Annyce Davis
 
PPTX
Selenium-Locators
Mithilesh Singh
 
PPTX
Software testing principles
Ing. Donato Di Pierro
 
PPT
Manual testing concepts course 1
Raghu Kiran
 
PPTX
QA Best Practices in Agile World_new
Praveen Dosapati (CSM)
 
PPT
Spring Boot in Action
Alex Movila
 
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
UNIT TESTING
Marius Crisan
 
Understanding Unit Testing
ikhwanhayat
 
functional testing
bharathanche
 
UNIT TESTING PPT
suhasreddy1
 
Agile QA and Testing process
Gloria Stoilova
 
Arquitetura de Automação de Teste
Elias Nogueira
 
Selenium IDE LOCATORS
Mindfire Solutions
 
The Test Pyramid
Thiago Ghisi
 
How to Automate API Testing
Bruno Pedro
 
Building a Test Automation Strategy for Success
Lee Barnes
 
Unit tests & TDD
Dror Helper
 
Unit Testing Concepts and Best Practices
Derek Smith
 
Static Code Analysis
Annyce Davis
 
Selenium-Locators
Mithilesh Singh
 
Software testing principles
Ing. Donato Di Pierro
 
Manual testing concepts course 1
Raghu Kiran
 
QA Best Practices in Agile World_new
Praveen Dosapati (CSM)
 
Spring Boot in Action
Alex Movila
 

Similar to Unit & integration testing (20)

PDF
What Is Unit Testing A Complete Guide With Examples.pdf
Jace Reed
 
PDF
What Is Unit Testing_ A Complete Guide With Examples.pdf
Steve Wortham
 
PDF
How Unit Testing Strengthens Software Reliability
Shubham Joshi
 
PPTX
Software Testing Strategies ,Validation Testing and System Testing.
Tanzeem Aslam
 
PDF
Unit Testing & TDD Training for Mobile Apps
Marcelo Busico
 
PPTX
Object Oriented Testing
AMITJain879
 
PDF
TDD Workshop UTN 2012
Facundo Farias
 
PPTX
Unit testing & TDD concepts with best practice guidelines.
Mohamed Taman
 
PPTX
Software testing
Bhagyashree pathak
 
PPS
Why Unit Testingl
priya_trivedi
 
PPS
Why unit testingl
Priya Sharma
 
PPS
Why Unit Testingl
priya_trivedi
 
PPTX
Unit testing
Vinod Wilson
 
PPS
Test Process
tokarthik
 
PPT
Software testing
Nitin Dhanuka
 
PPT
Testing and Mocking Object - The Art of Mocking.
Deepak Singhvi
 
PDF
Unit testing, principles
Renato Primavera
 
PPS
Unit Testing
Anuj Arora
 
DOC
Testing
poojadatt
 
What Is Unit Testing A Complete Guide With Examples.pdf
Jace Reed
 
What Is Unit Testing_ A Complete Guide With Examples.pdf
Steve Wortham
 
How Unit Testing Strengthens Software Reliability
Shubham Joshi
 
Software Testing Strategies ,Validation Testing and System Testing.
Tanzeem Aslam
 
Unit Testing & TDD Training for Mobile Apps
Marcelo Busico
 
Object Oriented Testing
AMITJain879
 
TDD Workshop UTN 2012
Facundo Farias
 
Unit testing & TDD concepts with best practice guidelines.
Mohamed Taman
 
Software testing
Bhagyashree pathak
 
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Priya Sharma
 
Why Unit Testingl
priya_trivedi
 
Unit testing
Vinod Wilson
 
Test Process
tokarthik
 
Software testing
Nitin Dhanuka
 
Testing and Mocking Object - The Art of Mocking.
Deepak Singhvi
 
Unit testing, principles
Renato Primavera
 
Unit Testing
Anuj Arora
 
Testing
poojadatt
 
Ad

Recently uploaded (20)

PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Ad

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/