SlideShare una empresa de Scribd logo
1 de 64
Descargar para leer sin conexión
Tratto da una storia vera…
A QA engineer walks into a bar. Orders a beer.
Orders 0 beers. Orders 99999999999 beers.
Orders a lizard. Orders -1 beers. Orders a
ueicbksjdhd. 

First real customer walks in and asks where the
bathroom is. The bar bursts into flames, killing
everyone.
Stefano Ottaviani

Software Engineer

@Ste8

stefano@smartmobile.it

steott@gmail.com
About Me
About You
•Chi è

• Sviluppatore

• Tester

• Project Manager / Imprenditore / …

• Altro

•Chi scrive già test automatici?

•Chi sa cosa sono i test automatici?

•Chi non sa cosa sono?
About Your Company
Come considera la scrittura di test automatici?

•Ignora l’esistenza dell’argomento

•Importanti al pari (o più) dello sviluppo

•Meno dello sviluppo, ma comunque importanti

•Superflui

•Dannosi
WHO?
Illustrations by Lisa Dzera
TesterDeveloper User
“A first major mistake
people make is thinking
that the testing team is
responsible for assuring
quality”
–Brian Marick
Developer, Tester e Utenti:

i Developer sono i primi a poter
accorgersi dei problemi e a poterli
correggere
WHY?
SOFTWARE
SOFTWARE EVERYWHERE
SOFTWARE
SOFTWARE EVERYWHERE
BOKEN SOFTWARE EVERYWHEREBOKEN SOFTWARE EVERYWHERE
BROKEN SOFTWAREBROKEN SOFTWARE
Altra storia… vera!
…spot the bug!
for (

var referenceDay = startDay; 

referenceDay < endDay; 

referenceDay = referenceDay.AddDays(1))
{

}
…e altri benefici!
Requisiti male interpretati
WHAT?
Tipi di test
• Unit testing

• Integration testing

• End-to-end testing / UI Testing

• Functional testing

• API testing

• Property Based Testing

• Mutation testing

• Smoke testing
• Acceptance testing

• Performance Testing

• Load testing

• Stress testing

• Security testing

• Usability testing

• Accessibility testing

• …
Tipi di test
• Unit testing
• Integration testing
• End-to-end testing / UI Testing
• Functional testing

• API testing

• Property Based Testing

• Mutation testing

• Smoke testing
• Acceptance testing

• Performance Testing

• Load testing

• Stress testing

• Security testing

• Usability testing

• Accessibility testing

• …
Metodologie
• TDD (Test Driven Development)

=> Red / Green / Refactor

• BDD (Behavior Driven Development)

=> Given / When / Then

• Test First

• ….
Metodologie
• TDD (Test Driven Development)

=> Red / Green / Refactor

• BDD (Behavior Driven Development)

=> Given / When / Then

• Test First
• ….
Definizione di Unit Test (1/2)
A unit test is an automated piece of code
that invokes a unit of work in the system and
then checks a single assumption about the
behavior of that unit of work.
http://artofunittesting.com/definition-of-a-unit-test/
Definizione di Unit Test (2/2)
A unit of work is a single logical functional
use case in the system that can be invoked
by some public interface (in most cases). A
unit of work can span a single method, a
whole class or multiple classes working
together to achieve one single logical
purpose that can be verified.
http://artofunittesting.com/definition-of-a-unit-test/
Un buon Unit Test: (1/2)
1.Able to be fully automated

2.Has full control over all the pieces running 

(Use mocks or stubs to achieve this isolation when needed)

3.Can be run in any order if part of many other tests

4.Runs in memory 

(no DB or File access, for example)

5.Consistently returns the same result 

(You always run the same test, so no random numbers, for
example. Save those for integration or range tests)
Un buon Unit Test: (2/2)
6.Runs fast

7.Tests a single logical concept in the system

8.Readable

9.Maintainable

10.Trustworthy 

(when you see its result, you don’t need to debug the
code just to be sure)
VS
Tester knows about internals and 

exploit that knowledge

Based on code analysis

•Statement coverage

•Branch coverage

•Condition coverage

•Basis path coverage 

=> Cyclomatic complexity
Tester does not know anything about 

the test object internal
Focuses on functional requirements



Based on input domain analysis

- Equivalence partitioning

- Boundary value analysis
Integration Test
• Usano una o più dipendenze “reali” del sistema testato

• real System Time (e.g. DateTime.Now),

• real File System

• real Database

• real Web Services

• Non veloci come gli Unit Test

• Non consistenti, possono ritornare valori diversi a
causa delle loro dipendenze (es. dal System Time)
Test End-to-End
Ensure that the integrated components of an application function as
expected. The entire application is tested in a real-world scenario such
as communicating with the database, network, hardware and other
applications. 

For example, a simplified end-to-end testing of an email application might
involve:

• Logging in to the application

• Accessing the inbox

• Opening and closing the mailbox

• Composing, forwarding or replying to email

• Checking the sent items

• Logging out of the application
HOW?
String Calculator

KATA
(by Roy Osherove)
“1,2” => 3

“1,3,4” => 8
1° step
Create a simple String calculator with a method int Add(string numbers)

1. The method can take 0, 1 or 2 numbers, and will return their sum (for an
empty string it will return 0) for example “” or “1” or “1,2”

2. Start with the simplest test case of an empty string and move to 1 and two
numbers

3. Remember to solve things as simply as possible so that you force yourself
to write tests you did not think about

4. Remember to refactor after each passing test
2° step
Allow the Add method to handle 

an unknown amount of numbers.
3° step
Allow the Add method to handle new lines between numbers
(instead of commas).

the following input is ok: "1n2,3" (will equal 6)

the following input is NOT ok: "1,n" (not need to prove it - just
clarifying)
4° step
Support different delimiters

1. to change a delimiter, the beginning of the string will contain
a separate line that looks like this: “//[delimiter]
n[numbers…]” for example “//;n1;2” should return 3 where
the default delimiter is ‘;’ .

2. the first line is optional. all existing scenarios should still be
supported
5° step
Calling Add with a negative number will throw an exception
“negatives not allowed” - and the negative that was passed.

If there are multiple negatives, show all of them in the exception
message.
6° step
Continua su

https://osherove.com/tdd-kata-1
PRICE Calculator

KATA
RECAP!
1. Individuazione Bug
2. Sviluppo più veloce 

senza andare in debug
3. Sviluppo più veloce senza dipendere dai

tempi di riposta dei sistemi esterni

(database, webservice, …)
4. Non dover attendere lo sviluppo di

dipendenze esterne

(database, webservice, …)
5. Suite di test di regressione
6. Feedback rapido e “visivo”
7. Refactoring
8. Scervellarsi di meno con le 

“Boundary conditions”
9. Miglior design del codice

(modularizzazione, coupling, 

Single Responsibility Principle, …)
10. Aiuto nelle Code Review
11. Evitare il “blocco dello scrittore”
(specialmente con TDD)
12. Mettersi nei “panni” degli
utilizzatori delle nostre API
13. Continuous Integration
14. Test utilizzabili come
esempi e documentazione
15. Confidenza
16. Qualche volta una gioia!
“Testing shows the presence,
not the absence of bugs.”
–Edsger W. Dijkstra
… ma ricordando che:
WHEN?
WHERE?
DOMANDE?

Más contenido relacionado

La actualidad más candente

Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingJoe Tremblay
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminardunglinh111
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Test Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingTest Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingChamil Jeewantha
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven developmentStephen Fuqua
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
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 WorldDror Helper
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done RightBrian Fenton
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit TestingShaun Abram
 
Writing good unit test
Writing good unit testWriting good unit test
Writing good unit testLucy Lu
 

La actualidad más candente (20)

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 Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
 
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
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Test Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingTest Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programming
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
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
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Writing good unit test
Writing good unit testWriting good unit test
Writing good unit test
 

Similar a Introduzione allo Unit Testing

Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptxskknowledge
 
Software testing introduction
Software testing introductionSoftware testing introduction
Software testing introductionSriman Eshwar
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...TEST Huddle
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1Blue Elephant Consulting
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support developmentChema del Barco
 
lec-11 Testing.ppt
lec-11 Testing.pptlec-11 Testing.ppt
lec-11 Testing.pptdebjani12
 

Similar a Introduzione allo Unit Testing (20)

Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptx
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software testing introduction
Software testing introductionSoftware testing introduction
Software testing introduction
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
Testing 101
Testing 101Testing 101
Testing 101
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
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
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Creating testing tools to support development
Creating testing tools to support developmentCreating testing tools to support development
Creating testing tools to support development
 
Debugging
DebuggingDebugging
Debugging
 
lec-11 Testing.ppt
lec-11 Testing.pptlec-11 Testing.ppt
lec-11 Testing.ppt
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Unit testing
Unit testingUnit testing
Unit testing
 

Más de Stefano Ottaviani

Accessibility Days: esperienze e condivisioni per l'accessibilità
Accessibility Days: esperienze e condivisioni per l'accessibilitàAccessibility Days: esperienze e condivisioni per l'accessibilità
Accessibility Days: esperienze e condivisioni per l'accessibilitàStefano Ottaviani
 
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)Stefano Ottaviani
 
Le meta-community: quando l'unione fa la forza
Le meta-community: quando l'unione fa la forzaLe meta-community: quando l'unione fa la forza
Le meta-community: quando l'unione fa la forzaStefano Ottaviani
 
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-PlatformVisual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-PlatformStefano Ottaviani
 
Save ourselves with unit testing :)
Save ourselves with unit testing :)Save ourselves with unit testing :)
Save ourselves with unit testing :)Stefano Ottaviani
 
Programmiamo iPhone e iPad (e non solo!) con MonoTouch
Programmiamo iPhone e iPad (e non solo!) con MonoTouchProgrammiamo iPhone e iPad (e non solo!) con MonoTouch
Programmiamo iPhone e iPad (e non solo!) con MonoTouchStefano Ottaviani
 
Utilizzare Windows Vista come Software Developer
Utilizzare Windows Vista come Software DeveloperUtilizzare Windows Vista come Software Developer
Utilizzare Windows Vista come Software DeveloperStefano Ottaviani
 
Sviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailSviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailStefano Ottaviani
 
Generazione Dinamica di Codice in .NET
Generazione Dinamica di Codice in .NETGenerazione Dinamica di Codice in .NET
Generazione Dinamica di Codice in .NETStefano Ottaviani
 

Más de Stefano Ottaviani (12)

Accessibility Days: esperienze e condivisioni per l'accessibilità
Accessibility Days: esperienze e condivisioni per l'accessibilitàAccessibility Days: esperienze e condivisioni per l'accessibilità
Accessibility Days: esperienze e condivisioni per l'accessibilità
 
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)
Come organizzare un evento in cui nessuno sia escluso (versione ICM Summit)
 
Le meta-community: quando l'unione fa la forza
Le meta-community: quando l'unione fa la forzaLe meta-community: quando l'unione fa la forza
Le meta-community: quando l'unione fa la forza
 
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-PlatformVisual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
Visual Studio 2015: novità per gli sviluppatori iOS, Android e Cross-Platform
 
Un anno di DevMarche
Un anno di DevMarcheUn anno di DevMarche
Un anno di DevMarche
 
Mobile e Smart Client
Mobile e Smart ClientMobile e Smart Client
Mobile e Smart Client
 
Save ourselves with unit testing :)
Save ourselves with unit testing :)Save ourselves with unit testing :)
Save ourselves with unit testing :)
 
MonoTouch, un anno dopo
MonoTouch, un anno dopoMonoTouch, un anno dopo
MonoTouch, un anno dopo
 
Programmiamo iPhone e iPad (e non solo!) con MonoTouch
Programmiamo iPhone e iPad (e non solo!) con MonoTouchProgrammiamo iPhone e iPad (e non solo!) con MonoTouch
Programmiamo iPhone e iPad (e non solo!) con MonoTouch
 
Utilizzare Windows Vista come Software Developer
Utilizzare Windows Vista come Software DeveloperUtilizzare Windows Vista come Software Developer
Utilizzare Windows Vista come Software Developer
 
Sviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRailSviluppo Web Agile Con MonoRail
Sviluppo Web Agile Con MonoRail
 
Generazione Dinamica di Codice in .NET
Generazione Dinamica di Codice in .NETGenerazione Dinamica di Codice in .NET
Generazione Dinamica di Codice in .NET
 

Último

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Último (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Introduzione allo Unit Testing

  • 1.
  • 2. Tratto da una storia vera… A QA engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 99999999999 beers. Orders a lizard. Orders -1 beers. Orders a ueicbksjdhd. First real customer walks in and asks where the bathroom is. The bar bursts into flames, killing everyone.
  • 4. About You •Chi è • Sviluppatore • Tester • Project Manager / Imprenditore / … • Altro •Chi scrive già test automatici? •Chi sa cosa sono i test automatici? •Chi non sa cosa sono?
  • 5. About Your Company Come considera la scrittura di test automatici? •Ignora l’esistenza dell’argomento •Importanti al pari (o più) dello sviluppo •Meno dello sviluppo, ma comunque importanti •Superflui •Dannosi
  • 7.
  • 8. Illustrations by Lisa Dzera TesterDeveloper User
  • 9. “A first major mistake people make is thinking that the testing team is responsible for assuring quality” –Brian Marick Developer, Tester e Utenti:
 i Developer sono i primi a poter accorgersi dei problemi e a poterli correggere
  • 10. WHY?
  • 12. BOKEN SOFTWARE EVERYWHEREBOKEN SOFTWARE EVERYWHERE BROKEN SOFTWAREBROKEN SOFTWARE
  • 13.
  • 15.
  • 16.
  • 17. …spot the bug! for (
 var referenceDay = startDay; 
 referenceDay < endDay; 
 referenceDay = referenceDay.AddDays(1)) {
 }
  • 18. …e altri benefici! Requisiti male interpretati
  • 19. WHAT?
  • 20. Tipi di test • Unit testing • Integration testing • End-to-end testing / UI Testing • Functional testing • API testing • Property Based Testing • Mutation testing • Smoke testing • Acceptance testing • Performance Testing • Load testing • Stress testing • Security testing • Usability testing • Accessibility testing • …
  • 21. Tipi di test • Unit testing • Integration testing • End-to-end testing / UI Testing • Functional testing • API testing • Property Based Testing • Mutation testing • Smoke testing • Acceptance testing • Performance Testing • Load testing • Stress testing • Security testing • Usability testing • Accessibility testing • …
  • 22. Metodologie • TDD (Test Driven Development)
 => Red / Green / Refactor • BDD (Behavior Driven Development)
 => Given / When / Then • Test First • ….
  • 23. Metodologie • TDD (Test Driven Development)
 => Red / Green / Refactor • BDD (Behavior Driven Development)
 => Given / When / Then • Test First • ….
  • 24.
  • 25. Definizione di Unit Test (1/2) A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. http://artofunittesting.com/definition-of-a-unit-test/
  • 26. Definizione di Unit Test (2/2) A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified. http://artofunittesting.com/definition-of-a-unit-test/
  • 27. Un buon Unit Test: (1/2) 1.Able to be fully automated 2.Has full control over all the pieces running 
 (Use mocks or stubs to achieve this isolation when needed) 3.Can be run in any order if part of many other tests 4.Runs in memory 
 (no DB or File access, for example) 5.Consistently returns the same result 
 (You always run the same test, so no random numbers, for example. Save those for integration or range tests)
  • 28. Un buon Unit Test: (2/2) 6.Runs fast 7.Tests a single logical concept in the system 8.Readable 9.Maintainable 10.Trustworthy 
 (when you see its result, you don’t need to debug the code just to be sure)
  • 29. VS Tester knows about internals and 
 exploit that knowledge
 Based on code analysis •Statement coverage •Branch coverage •Condition coverage •Basis path coverage 
 => Cyclomatic complexity Tester does not know anything about 
 the test object internal Focuses on functional requirements
 
 Based on input domain analysis - Equivalence partitioning - Boundary value analysis
  • 30. Integration Test • Usano una o più dipendenze “reali” del sistema testato • real System Time (e.g. DateTime.Now), • real File System • real Database • real Web Services • Non veloci come gli Unit Test • Non consistenti, possono ritornare valori diversi a causa delle loro dipendenze (es. dal System Time)
  • 31. Test End-to-End Ensure that the integrated components of an application function as expected. The entire application is tested in a real-world scenario such as communicating with the database, network, hardware and other applications. For example, a simplified end-to-end testing of an email application might involve: • Logging in to the application • Accessing the inbox • Opening and closing the mailbox • Composing, forwarding or replying to email • Checking the sent items • Logging out of the application
  • 32.
  • 33. HOW?
  • 36. 1° step Create a simple String calculator with a method int Add(string numbers) 1. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2” 2. Start with the simplest test case of an empty string and move to 1 and two numbers 3. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about 4. Remember to refactor after each passing test
  • 37. 2° step Allow the Add method to handle 
 an unknown amount of numbers.
  • 38. 3° step Allow the Add method to handle new lines between numbers (instead of commas). the following input is ok: "1n2,3" (will equal 6) the following input is NOT ok: "1,n" (not need to prove it - just clarifying)
  • 39. 4° step Support different delimiters 1. to change a delimiter, the beginning of the string will contain a separate line that looks like this: “//[delimiter] n[numbers…]” for example “//;n1;2” should return 3 where the default delimiter is ‘;’ . 2. the first line is optional. all existing scenarios should still be supported
  • 40. 5° step Calling Add with a negative number will throw an exception “negatives not allowed” - and the negative that was passed. If there are multiple negatives, show all of them in the exception message.
  • 43.
  • 46. 2. Sviluppo più veloce 
 senza andare in debug
  • 47. 3. Sviluppo più veloce senza dipendere dai
 tempi di riposta dei sistemi esterni
 (database, webservice, …)
  • 48. 4. Non dover attendere lo sviluppo di
 dipendenze esterne
 (database, webservice, …)
  • 49. 5. Suite di test di regressione
  • 50. 6. Feedback rapido e “visivo”
  • 52. 8. Scervellarsi di meno con le 
 “Boundary conditions”
  • 53. 9. Miglior design del codice
 (modularizzazione, coupling, 
 Single Responsibility Principle, …)
  • 54. 10. Aiuto nelle Code Review
  • 55. 11. Evitare il “blocco dello scrittore” (specialmente con TDD)
  • 56. 12. Mettersi nei “panni” degli utilizzatori delle nostre API
  • 58. 14. Test utilizzabili come esempi e documentazione
  • 60. 16. Qualche volta una gioia!
  • 61. “Testing shows the presence, not the absence of bugs.” –Edsger W. Dijkstra … ma ricordando che:
  • 62. WHEN?