SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Unit Testing 
By Mohamad Asmar a.k.a DaiGooR
Me! 
Mohamed AsmerDeveloper 
daigoor@gmail.com 
www.daigoor.com@daigoor 
(+970) 598 917 280
Developer life ! 
the more pressure you feel, the fewer tests you writes. The fewer tests you write, the less productive you are and the less stable your code becomes. The less productive and accurate you are, the more pressure you feel.
Def. 
Wikipedia :unit testingis asoftware testingmethod by which individual units ofsource code 
In a simple way … validate each and every unit of the software perform as designed.
Def. Cont. 
A Unit is the smallest part of code 
›{function or procedure} 
›The smallest part that can be compiled by it self.
Ex 
public int stringToInt( String str ){ return Integer.parseInt(str); } 
stringToInt(null); 
stringToInt(“TEXT”) 
stringToInt(“1234567890987654321”)
Why ? 
Without it defects will appear at the end of the cycle! 
Trace bugs is time consuming , hard and complex 
Check new feature if they are feasible 
Check input and output values 
Correct outputs fast
Why ? -_- 
Reduce future cost ! 
Faster development 
Better design 
Faster debugging 
Excellent regression tool + 
it provide sort of documentation
Categories 
White-Box : function exe and checked 
Black-Box : input/output & app-interface
Types 
Positive test (end user testing) 
›Valid parameter 
Negative test 
›Not valid parameter
Ex 
public int stringToInt( String str ){ return Integer.parseInt(str); } 
stringToInt(null)//N 
stringToInt(“TEXT”)//N 
stringToInt(“1234567890987654321”)//N 
stringToInt(“1234”)//P
When to write the test? 
“Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.”...
story 
:$
Traditional Testing Strategies 
Print Statements 
Use of Debugger 
Debugger Expressions
Ex. 
... List<?> getVersionsForProductId(Long id){ … return List<?> } 
The Tests That AreNeeded 
Startingfromtheeasiesttothehardest: 
Ifthere’snoproductforthatid,thenanexceptionisthrown. 
Ifthere’snoversionsforavalidproductid,thenanemptylistisreturned. 
Ifthereareversionsforaproductid,thenanon-emptylistofalltheversionsisreturned.
Live Show 
Eclipse 
IntelliJ Idea
Keep Unit tests small and fast We should run them after each checkin 
keep them UN-dependent They should not depend on each other 
They should be simple 
Fix error immediately
Its all about unit There should be a test class per each class .. no more no less ! You should not right an application to test another application. 
Start with the simple test 
Code convention

Contenu connexe

Tendances

Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
Mike Clement
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 
Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...
Timo Stollenwerk
 

Tendances (19)

07 flow control
07   flow control07   flow control
07 flow control
 
03 conditions loops
03   conditions loops03   conditions loops
03 conditions loops
 
Introduction to unit testing in python
Introduction to unit testing in pythonIntroduction to unit testing in python
Introduction to unit testing in python
 
Md04 flow control
Md04 flow controlMd04 flow control
Md04 flow control
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Using Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit TestingUsing Rhino Mocks for Effective Unit Testing
Using Rhino Mocks for Effective Unit Testing
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Java Control Statements
Java Control StatementsJava Control Statements
Java Control Statements
 
Golang dot-testing-lite
Golang dot-testing-liteGolang dot-testing-lite
Golang dot-testing-lite
 
White Box Testing (Introduction to)
White Box Testing (Introduction to)White Box Testing (Introduction to)
White Box Testing (Introduction to)
 
Template Method Design Pattern
Template Method Design PatternTemplate Method Design Pattern
Template Method Design Pattern
 
Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...Python-nose: A unittest-based testing framework for Python that makes writing...
Python-nose: A unittest-based testing framework for Python that makes writing...
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Exception handling in python
Exception handling in pythonException handling in python
Exception handling in python
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 

Similaire à Unit testing.pptx [repaired]

Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
Babul Mirdha
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
Vladimir Ivanov
 

Similaire à Unit testing.pptx [repaired] (20)

DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
 
maXbox Starter 36 Software Testing
maXbox Starter 36 Software TestingmaXbox Starter 36 Software Testing
maXbox Starter 36 Software Testing
 
Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)Test Driven iOS Development (TDD)
Test Driven iOS Development (TDD)
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
[XCode] Automating UI Testing
[XCode] Automating UI Testing[XCode] Automating UI Testing
[XCode] Automating UI Testing
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Testing - Is This Even a Thing?
Testing - Is This Even a Thing?Testing - Is This Even a Thing?
Testing - Is This Even a Thing?
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
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
 
Mutation Testing: Testing your tests
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your tests
 
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
 

Dernier

Dernier (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Unit testing.pptx [repaired]

  • 1. Unit Testing By Mohamad Asmar a.k.a DaiGooR
  • 2. Me! Mohamed AsmerDeveloper daigoor@gmail.com www.daigoor.com@daigoor (+970) 598 917 280
  • 3. Developer life ! the more pressure you feel, the fewer tests you writes. The fewer tests you write, the less productive you are and the less stable your code becomes. The less productive and accurate you are, the more pressure you feel.
  • 4. Def. Wikipedia :unit testingis asoftware testingmethod by which individual units ofsource code In a simple way … validate each and every unit of the software perform as designed.
  • 5. Def. Cont. A Unit is the smallest part of code ›{function or procedure} ›The smallest part that can be compiled by it self.
  • 6. Ex public int stringToInt( String str ){ return Integer.parseInt(str); } stringToInt(null); stringToInt(“TEXT”) stringToInt(“1234567890987654321”)
  • 7. Why ? Without it defects will appear at the end of the cycle! Trace bugs is time consuming , hard and complex Check new feature if they are feasible Check input and output values Correct outputs fast
  • 8. Why ? -_- Reduce future cost ! Faster development Better design Faster debugging Excellent regression tool + it provide sort of documentation
  • 9.
  • 10. Categories White-Box : function exe and checked Black-Box : input/output & app-interface
  • 11. Types Positive test (end user testing) ›Valid parameter Negative test ›Not valid parameter
  • 12. Ex public int stringToInt( String str ){ return Integer.parseInt(str); } stringToInt(null)//N stringToInt(“TEXT”)//N stringToInt(“1234567890987654321”)//N stringToInt(“1234”)//P
  • 13. When to write the test? “Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.”...
  • 15. Traditional Testing Strategies Print Statements Use of Debugger Debugger Expressions
  • 16. Ex. ... List<?> getVersionsForProductId(Long id){ … return List<?> } The Tests That AreNeeded Startingfromtheeasiesttothehardest: Ifthere’snoproductforthatid,thenanexceptionisthrown. Ifthere’snoversionsforavalidproductid,thenanemptylistisreturned. Ifthereareversionsforaproductid,thenanon-emptylistofalltheversionsisreturned.
  • 17. Live Show Eclipse IntelliJ Idea
  • 18. Keep Unit tests small and fast We should run them after each checkin keep them UN-dependent They should not depend on each other They should be simple Fix error immediately
  • 19. Its all about unit There should be a test class per each class .. no more no less ! You should not right an application to test another application. Start with the simple test Code convention