SlideShare a Scribd company logo
SOFTWARE QUALITY
VIA UNIT TESTING
Shaun Abram
April 20, 2013




Email: Shaun@Abram.com                                  Blog: shaunabram.com
Twitter: @shaunabram                          LinkedIn: linkedin.com/in/sabram

                 These slides available at shaunabram.com/dcc13
2




Software Quality via Unit Testing


The value of software design
Automated testing
Clean code




                          Goal:
                Deliver value to our users
3




Software Quality via Unit Testing


The value of software design
4




Why should we care about „good‟ design in software?


     We need less focus on quality so we can
     add more features



                                     Do we really need unit tests?




           Refactoring doesn‟t change what the code
           does, so why bother?




                        How do you respond?
5




Why should we care about „good‟ design in software?

Take the moral high ground?
6




Why should we care about „good‟ design in software?




              We need to have economic reasons




   Remember: Our goal is to deliver   value to our users
7




What is Quality in software anyway?

    Intuitive GUI
    Few defects
    Modular Design
8




What is Quality in software anyway?

    Intuitive GUI
    Few defects      Visible to user

    Modular Design   Transparent to user
9




Fowler‟s Design Stamina Hypothesis
10




Technical debt
The eventual consequences of poor design in a codebase
11




Technical debt
The eventual consequences of poor design in a codebase




Interest payments can come in the form of:
1. Bugs
2. Just understanding what the heck the current code does
3. Refactoring
4. Completing unfinished work
12




Technical debt
Pay down?
Accept?




                 But, don‟t build bad on top of bad…
Design Stamina
Design




                            stamina to
         continually and consistently deliver functionality
              faster and with less bugs to our users




                                                Business value to our clients
14




Clean code that works


• The value of software design
• Automated testing
15




Unit testing
A unit test is a piece of code that executes a specific
functionality („unit‟) in the code, and
• Confirms the behavior or result is as expected.
• Determines if code is „fit for use‟


Example…
1
•




    1
1
1
Software Quality via Unit Testing
2
2
2
2
25




What unit tests provide
Unit tests don‟t necessarily help find bugs.
Instead, unit tests:
  • Drive design
26




What unit tests provide
Unit tests don‟t necessarily help find bugs.
Instead, unit tests:
  • Drive design


    • The tests act as the first user of the code, making you think about:
       • What should this code do
       • Border conditions (0, null, -ve, too big)


    • Force you to use good design:
       • Short, focused methods
       • Dependency Injection



    • Writing a class is different from using a class!
27




What unit tests provide
Unit tests don‟t necessarily help find bugs.
Instead, unit tests:
  • Drive design
  • Act as safety buffers by finding regression bugs
  • Provide documentation
28




What unit tests provide
Unit tests don‟t necessarily help find bugs.
Instead, unit tests:
  • Drive design
  • Act as safety buffers by finding regression bugs
  • Provide documentation



Can also be used on legacy codebases
29




Unit testing limitations
1. Can not prove the absence of bugs
2. Lot‟s of code (x3-5)
3. Some things difficult to test
30




So should we unit test?

Not only should we unit test,
We should let unit tests drive development and design…

             Test Driven Development (TDD)
31




Test Driven Development (TDD)
32




Test Driven Development (TDD)
33




Test Driven Development (TDD)
34




Test Driven Development (TDD)




        Red - Green – Refactor: the TDD Mantra
        No new functionality without a failing test
          No refactoring without passing tests
35




Test Driven Development (TDD) Example
Write a simple StringCalculator class with a method
       Integer add(String numbers)

A String of comma separated numbers should return their
sum e.g. “1,2,10” should return 13.
A single number String should return that number e.g. “3”
should return 3
An empty String should return 0

For brevity, our test will focus on valid inputs.
36




Test Driven Development (TDD) Example
Write a simple StringCalculator class with a method
       Integer add(String numbers)




                      Code demo…
3
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Refactor?
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Refactor?
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
Software Quality via Unit Testing
These tests act like the original
developer looking over your
shoulder and advising you, long
after that developer has left…
58




Test Driven Development (TDD)




        Red - Green – Refactor: the TDD Mantra
        No new functionality without a failing test
          No refactoring without passing tests
59




Clean code that works


• The value of software design
• Automated testing
60




Clean code that works


• The value of software design
• Automated testing
• Clean code
61




• Feedback…




• XKCD
6
63

Code Smells
What are code smells?

 “Certain structures in code suggest (sometimes they scream for) the
                        possibility of refactoring.”
        Martin Fowler. Refactoring: Improving the design of existing code
64

Code Smells

• Duplicated code
• Long switch/if statements
• Long methods
Even one line methods can be OK:
if ( (account != null) && ( (account.getBalance() > 0) || (!account.overdraftLimitReached()) ) {
             …
}


if (account.hasFundsAvailable()) {
            …
}
65

Code Smells

• Duplicated code
• Long switch/if statements
• Long methods
• Poor method names
     int process(int id) { //bad!
     int calculateAccountBalance(int accountID) { //better
66

Code Smells

• Duplicated code
• Long switch/if statements
• Long methods
• Poor method names
• In-line comments
• Large classes
  • Symptoms
     • Too many methods (>10 public?)
     • Too many instance variables – is every instance variable used in every
       method?
  • Solutions
     • Eliminate redundancy / duplicated code
     • Extract new/sub classes
67




Clear Code

             Make the intent of your code clear
   Code should be clear, concise and easy to understand


How many times will the code you are about to write be read?


 Studies show poor readability correlates strongly with defect
                         density1


                  Avoid attrition & complete re-writes
      1"Learning a Metric for Code Readability," IEEE Transactions on Software Engineering, 09 Nov.
      2009. IEEE computer Society Digital Library. IEEE Computer Society
68




Summary
• Good design gives us the stamina to continually and
  consistently deliver business value
• Unit tests are an integral part of good design; TDD is even
  better
• Good design can also simply be cleaner code;
  Aggressively refactor to achieve this!



                       Final thought:
           Every time you are in a piece of code,
            just make one small improvement!
69


  Recommended Reading
Test Driven Development             Growing Object-Oriented
Kent Beck
                                    Software, Guided by Tests
                                    Freeman & Pryce




Refactoring: Improving the Design   Effective Unit Testing
of Existing Code                    Lasse Koskela

Martin Fowler, Kent Beck et. al.
Questions?




All slides available at: shaunabram.com/dcc13




Email: Shaun@Abram.com                              Blog: shaunabram.com
Twitter: @shaunabram                      LinkedIn: linkedin.com/in/sabram

                                                                             7

More Related Content

What's hot

Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
David Berliner
 
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
Dror Helper
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
Dave Bouwman
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
Shaun Abram
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
David Ehringer
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
Pablo Villar
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
Richard Paul
 
Unit testing
Unit testingUnit testing
Unit testing
Slideshare
 
Unit Testing Guidelines
Unit Testing GuidelinesUnit Testing Guidelines
Unit Testing Guidelines
Joel Hooks
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
XPDays
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
Unit testing
Unit testingUnit testing
Unit testing
princezzlove
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
Marius Crisan
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Mireia Sangalo
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
Paladin Web Services
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
Vitaliy Kulikov
 

What's hot (20)

Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
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 Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing Guidelines
Unit Testing GuidelinesUnit Testing Guidelines
Unit Testing Guidelines
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Unit testing
Unit testingUnit testing
Unit testing
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 

Similar to Software Quality via Unit Testing

xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
Justin Gordon
 
Test driven development
Test driven developmentTest driven development
Test driven development
Sunil Prasad
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
Seapine Software
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)
lqi
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code Quality
Saltmarch Media
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About Testing
Camille Bell
 
Agile Software Design
Agile Software DesignAgile Software Design
Agile Software Design
eduardomg23
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
Edorian
 
10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming
PostSharp Technologies
 
Technical debt management strategies
Technical debt management strategiesTechnical debt management strategies
Technical debt management strategies
Raquel Pau
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
Mahesh Salaria
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
nadeembtech
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Bill Buchan
 
11 best practices_for_peer_code_review
11 best practices_for_peer_code_review11 best practices_for_peer_code_review
11 best practices_for_peer_code_review
SmartBear Software
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java Project
GlobalLogic Ukraine
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
Kerry Buckley
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
satejsahu
 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Joseph Yoder
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
Peter Kofler
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 

Similar to Software Quality via Unit Testing (20)

xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code Quality
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About Testing
 
Agile Software Design
Agile Software DesignAgile Software Design
Agile Software Design
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
 
10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming10 Reasons You MUST Consider Pattern-Aware Programming
10 Reasons You MUST Consider Pattern-Aware Programming
 
Technical debt management strategies
Technical debt management strategiesTechnical debt management strategies
Technical debt management strategies
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Quality metrics and angular js applications
Quality metrics and angular js applicationsQuality metrics and angular js applications
Quality metrics and angular js applications
 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
 
11 best practices_for_peer_code_review
11 best practices_for_peer_code_review11 best practices_for_peer_code_review
11 best practices_for_peer_code_review
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java Project
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Topic production code
Topic production codeTopic production code
Topic production code
 

Recently uploaded

Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
Ivanti
 
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and DisadvantagesBLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
SAI KAILASH R
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
Management Institute of Skills Development
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
SynapseIndia
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
digitalxplive
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
Jimmy Lai
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
Matthias Neugebauer
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
CEPTES Software Inc
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Zilliz
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Torry Harris
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 

Recently uploaded (20)

Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 
July Patch Tuesday
July Patch TuesdayJuly Patch Tuesday
July Patch Tuesday
 
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and DisadvantagesBLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
 
Figma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdfFigma AI Design Generator_ In-Depth Review.pdf
Figma AI Design Generator_ In-Depth Review.pdf
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
 
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-InTrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
TrustArc Webinar - 2024 Data Privacy Trends: A Mid-Year Check-In
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
 
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python CodebaseEuroPython 2024 - Streamlining Testing in a Large Python Codebase
EuroPython 2024 - Streamlining Testing in a Large Python Codebase
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 

Software Quality via Unit Testing

  • 1. SOFTWARE QUALITY VIA UNIT TESTING Shaun Abram April 20, 2013 Email: Shaun@Abram.com Blog: shaunabram.com Twitter: @shaunabram LinkedIn: linkedin.com/in/sabram These slides available at shaunabram.com/dcc13
  • 2. 2 Software Quality via Unit Testing The value of software design Automated testing Clean code Goal: Deliver value to our users
  • 3. 3 Software Quality via Unit Testing The value of software design
  • 4. 4 Why should we care about „good‟ design in software? We need less focus on quality so we can add more features Do we really need unit tests? Refactoring doesn‟t change what the code does, so why bother? How do you respond?
  • 5. 5 Why should we care about „good‟ design in software? Take the moral high ground?
  • 6. 6 Why should we care about „good‟ design in software? We need to have economic reasons Remember: Our goal is to deliver value to our users
  • 7. 7 What is Quality in software anyway? Intuitive GUI Few defects Modular Design
  • 8. 8 What is Quality in software anyway? Intuitive GUI Few defects Visible to user Modular Design Transparent to user
  • 10. 10 Technical debt The eventual consequences of poor design in a codebase
  • 11. 11 Technical debt The eventual consequences of poor design in a codebase Interest payments can come in the form of: 1. Bugs 2. Just understanding what the heck the current code does 3. Refactoring 4. Completing unfinished work
  • 12. 12 Technical debt Pay down? Accept? But, don‟t build bad on top of bad…
  • 13. Design Stamina Design stamina to continually and consistently deliver functionality faster and with less bugs to our users Business value to our clients
  • 14. 14 Clean code that works • The value of software design • Automated testing
  • 15. 15 Unit testing A unit test is a piece of code that executes a specific functionality („unit‟) in the code, and • Confirms the behavior or result is as expected. • Determines if code is „fit for use‟ Example…
  • 16. 1
  • 17. 1
  • 18. 1
  • 19. 1
  • 21. 2
  • 22. 2
  • 23. 2
  • 24. 2
  • 25. 25 What unit tests provide Unit tests don‟t necessarily help find bugs. Instead, unit tests: • Drive design
  • 26. 26 What unit tests provide Unit tests don‟t necessarily help find bugs. Instead, unit tests: • Drive design • The tests act as the first user of the code, making you think about: • What should this code do • Border conditions (0, null, -ve, too big) • Force you to use good design: • Short, focused methods • Dependency Injection • Writing a class is different from using a class!
  • 27. 27 What unit tests provide Unit tests don‟t necessarily help find bugs. Instead, unit tests: • Drive design • Act as safety buffers by finding regression bugs • Provide documentation
  • 28. 28 What unit tests provide Unit tests don‟t necessarily help find bugs. Instead, unit tests: • Drive design • Act as safety buffers by finding regression bugs • Provide documentation Can also be used on legacy codebases
  • 29. 29 Unit testing limitations 1. Can not prove the absence of bugs 2. Lot‟s of code (x3-5) 3. Some things difficult to test
  • 30. 30 So should we unit test? Not only should we unit test, We should let unit tests drive development and design… Test Driven Development (TDD)
  • 34. 34 Test Driven Development (TDD) Red - Green – Refactor: the TDD Mantra No new functionality without a failing test No refactoring without passing tests
  • 35. 35 Test Driven Development (TDD) Example Write a simple StringCalculator class with a method Integer add(String numbers) A String of comma separated numbers should return their sum e.g. “1,2,10” should return 13. A single number String should return that number e.g. “3” should return 3 An empty String should return 0 For brevity, our test will focus on valid inputs.
  • 36. 36 Test Driven Development (TDD) Example Write a simple StringCalculator class with a method Integer add(String numbers) Code demo…
  • 37. 3
  • 57. These tests act like the original developer looking over your shoulder and advising you, long after that developer has left…
  • 58. 58 Test Driven Development (TDD) Red - Green – Refactor: the TDD Mantra No new functionality without a failing test No refactoring without passing tests
  • 59. 59 Clean code that works • The value of software design • Automated testing
  • 60. 60 Clean code that works • The value of software design • Automated testing • Clean code
  • 62. 6
  • 63. 63 Code Smells What are code smells? “Certain structures in code suggest (sometimes they scream for) the possibility of refactoring.” Martin Fowler. Refactoring: Improving the design of existing code
  • 64. 64 Code Smells • Duplicated code • Long switch/if statements • Long methods Even one line methods can be OK: if ( (account != null) && ( (account.getBalance() > 0) || (!account.overdraftLimitReached()) ) { … } if (account.hasFundsAvailable()) { … }
  • 65. 65 Code Smells • Duplicated code • Long switch/if statements • Long methods • Poor method names int process(int id) { //bad! int calculateAccountBalance(int accountID) { //better
  • 66. 66 Code Smells • Duplicated code • Long switch/if statements • Long methods • Poor method names • In-line comments • Large classes • Symptoms • Too many methods (>10 public?) • Too many instance variables – is every instance variable used in every method? • Solutions • Eliminate redundancy / duplicated code • Extract new/sub classes
  • 67. 67 Clear Code Make the intent of your code clear Code should be clear, concise and easy to understand How many times will the code you are about to write be read? Studies show poor readability correlates strongly with defect density1 Avoid attrition & complete re-writes 1"Learning a Metric for Code Readability," IEEE Transactions on Software Engineering, 09 Nov. 2009. IEEE computer Society Digital Library. IEEE Computer Society
  • 68. 68 Summary • Good design gives us the stamina to continually and consistently deliver business value • Unit tests are an integral part of good design; TDD is even better • Good design can also simply be cleaner code; Aggressively refactor to achieve this! Final thought: Every time you are in a piece of code, just make one small improvement!
  • 69. 69 Recommended Reading Test Driven Development Growing Object-Oriented Kent Beck Software, Guided by Tests Freeman & Pryce Refactoring: Improving the Design Effective Unit Testing of Existing Code Lasse Koskela Martin Fowler, Kent Beck et. al.
  • 70. Questions? All slides available at: shaunabram.com/dcc13 Email: Shaun@Abram.com Blog: shaunabram.com Twitter: @shaunabram LinkedIn: linkedin.com/in/sabram 7