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

More Related Content

What's hot

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
 

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

Similar to 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
 

Similar to 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,...
 

Recently uploaded

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

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