SlideShare a Scribd company logo
Making Software. Better.
Simple solutions to big business problems.
Test-Driven Development In Swift
by
@ameytavkar @javalnanda
Why do we test?
Why do we test?
● Confidence - Gain confidence in the system we are building.
● Verification - To verify what we create does what it’s supposed to do.
● Learning - Identify weak areas of the system.
Testing can be done manually or
can be automated.
Why Automation?
● Faster Regression Tests - Automated tools run significantly faster than us.
● Easier Refactoring - Shortened feedback loops helps us to improve our design much
easily
● Continuous Integration - Having automated tests makes integration painless and
significantly faster.
Should we write our tests
before
or
after
implementation?
Why writing tests after implementation is bad?
● Laziness - Once the system is tested manually, writing unit tests seems like a extra
effort.
● Lack of Discipline - Code written without considering testing rapidly becomes tightly
coupled and makes it hard to refactor in later stages.
● Compromise - Tests are generally influenced by the written code instead of the actual
user requirements.
Why should we test first?
Why should we test first?
● Loosely Coupled Code - We tend to make our modules independent which in turn
helps in creating loosely coupled code.
● Verification - We write the tests keeping the requirements in mind.
● Confidence - We gain confidence that we won’t be breaking any functionality in the
process of implementing new ones.
Test-Driven Development (TDD)
What is TDD?
High test coverage is not the end
goal of TDD, it’s a side effect of it.
Test first
=
Thinking
+
Designing
+
Writing test
Live Demo
Tic Tac Toe Requirements
1. A marker can be placed on any empty space of a 3×3 board.
○ Game engine should be able to create a 3x3 board on initialization
○ Game engine should be able to place a marker on a board
○ Game engine should not be able to place the marker on an already placed marker
2. Two Players can take turns marking the spaces on the board.
○ Game engine should have 2 players on initialization
○ On start player one takes the move
○ After move game engine should toggle player turns
Common Pitfalls in TDD
Common Pitfalls in TDD
● Not Testing Behaviors - Test behaviors not implementations
● Having Dependencies - Avoid tests that depend on each other
● Not Refactoring on Green - Don’t jump ahead to next tests without checking the need
to refactor once you get a green for a test.
Common Pitfalls in TDD (Cont.)
● Poor Readability - Never ignore the importance of naming the tests correctly. Tests
are also executable requirement spec. Treat them well and try to name it relevant to the
behaviour you are testing.
● Large Tests - Avoid testing more than one behaviour in a single unit test.
● Not Respecting Privacy - Don’t violate scope just because you are not able to test
something. If it is hard to write the test, its a sign of code smell.
What not to test?
● Private Methods - This is an implementation detail and the tests for the exposed
methods should be sufficient enough to cover the private ones
● External Library/Framework - The framework should be tested by its own developer!
● UI Design - Constraints, Layouts should be part of UI Tests
Best Practises
Best Practises
● Use a good architecture
● Use protocols to isolate class to test
● Write structured tests - Arrange, Act and Assert
● Don’t start with edge cases
● Always work on one test case at a time
● Avoid writing redundant tests
How to test Controllers
● Move the non-UI specific logic code out of the viewcontrollers
● Use dependency injection to your advantage
● Use closures to your advantage
How to Mock Dependencies using protocols?
● Find the method/behavior definition(s) on the object that you need to confirm
interactions with
● Create your own protocol to duplicate the definition(s)
● Create a fake object that implements that the protocol
● Use the fake objects in your tests
Tools that we recommend
● Unit Tests
○ Quick / Nimble
‐ https://github.com/Quick/Quick
‐ Helps in forcing the developer to write more english-like statements
● UI Automation
○ EarlGrey
○ https://github.com/google/EarlGrey
○ Synchronized UI Tests!
● Mocking
○ Cuckoo
‐ https://github.com/Brightify/Cuckoo
‐ Auto-generate your mocks in swift!
Conclusions
Conclusions
● Automation Tests are our friends
● Testing before implementation forces us to think about design.
● TDD Mantra - RED -> GREEN -> REFACTOR -> REPEAT
● Test early, Test Often!
● TDD isn’t about tests, its about design
● We have loosely coupled and highly cohesive code by following TDD Mantra
● Gain Confidence in the system
● High Code coverage
Thank You
United Kingdom
+44 203 603 7830
helloUK@equalexperts.com
Equal Experts UK Ltd
30 Brock Street
London NW1 3FG
India
+91 20 6607 7763
helloIndia@equalexperts.com
Equal Experts India Private Ltd
Office No. 4-C
Cerebrum IT Park No. B3
Kumar City, Kalyani Nagar
Pune, 411006
Canada
+1 403 775 4861
helloCanada@equalexperts.com
Equal Experts Devices Inc
205 - 279 Midpark way S.E.
T2X 1M2
Calgary, Alberta
Portugal
+351 211 378 414
helloPortugal@equalexperts.com
Equal Experts Portugal
Avenida Dom João II, Nº35
Edificio Infante 11ºA
1990-083 Parque das Nações
Lisboa – Portugal
Thank You
USA
+1 866-943-9737
helloUSA@equalexperts.com
Equal Experts Inc
1460 Broadway
New York
NY 10036
 
LinkedIn
linkedin.com/company/equal-experts
Twitter
@EqualExperts
Web
www.equalexperts.com
References
1. http://www.netobjectives.com/blogs/why-test-driven-development-really-isn%E2%80%
99t-test-first
2. https://8thlight.com/blog/uncle-bob/2014/04/30/When-tdd-does-not-work.html
3. https://vimeo.com/68375232
4. https://github.com/javalnanda/good-tdd-stuff
5. https://blog.eliperkins.me/mocks-in-swift-via-protocols/

More Related Content

What's hot

Tdd red-green-refactor
Tdd red-green-refactorTdd red-green-refactor
Tdd red-green-refactor
Francisco Iglesias Gómez
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
Vitaliy Kulikov
 
Tdd - Test Driven Development
Tdd - Test Driven DevelopmentTdd - Test Driven Development
Tdd - Test Driven Development
David Paluy
 
The art of being an agile programmer
The art of being an agile programmerThe art of being an agile programmer
The art of being an agile programmer
Claudia Rosu
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automation
gaoliang641
 
Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1
Jitendra Zaa
 
How not to suck at unit tests
How not to suck at unit testsHow not to suck at unit tests
How not to suck at unit tests
Benjamin Bishop
 
Unit test and continuous deployment
Unit test and continuous deploymentUnit test and continuous deployment
Unit test and continuous deployment
Luis Borbon
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Test driven development : software process
Test driven development : software process Test driven development : software process
Test driven development : software process
Amin Taheri
 
Android tdd
Android tddAndroid tdd
Android tdd
Nhan Cao
 
Testing strategies for legacy code
Testing strategies for legacy codeTesting strategies for legacy code
Testing strategies for legacy code
Alex Soto
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
Knoldus Inc.
 
Implementing Continous Deployment
Implementing Continous DeploymentImplementing Continous Deployment
Implementing Continous Deployment
arosien
 
Code Review
Code ReviewCode Review
Code Review
Mikalai Alimenkou
 
BugDay 2012 : The variety of Unit Testing #1
BugDay 2012 : The variety of Unit Testing #1BugDay 2012 : The variety of Unit Testing #1
BugDay 2012 : The variety of Unit Testing #1
Somkiat Puisungnoen
 
A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26
Julio Ramirez
 
Introduction to Continuous Delivery
Introduction to Continuous DeliveryIntroduction to Continuous Delivery
Introduction to Continuous Delivery
Giovanni Toraldo
 

What's hot (19)

Tdd red-green-refactor
Tdd red-green-refactorTdd red-green-refactor
Tdd red-green-refactor
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
Tdd - Test Driven Development
Tdd - Test Driven DevelopmentTdd - Test Driven Development
Tdd - Test Driven Development
 
The art of being an agile programmer
The art of being an agile programmerThe art of being an agile programmer
The art of being an agile programmer
 
General Tips
General TipsGeneral Tips
General Tips
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automation
 
Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1
 
How not to suck at unit tests
How not to suck at unit testsHow not to suck at unit tests
How not to suck at unit tests
 
Unit test and continuous deployment
Unit test and continuous deploymentUnit test and continuous deployment
Unit test and continuous deployment
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Test driven development : software process
Test driven development : software process Test driven development : software process
Test driven development : software process
 
Android tdd
Android tddAndroid tdd
Android tdd
 
Testing strategies for legacy code
Testing strategies for legacy codeTesting strategies for legacy code
Testing strategies for legacy code
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
 
Implementing Continous Deployment
Implementing Continous DeploymentImplementing Continous Deployment
Implementing Continous Deployment
 
Code Review
Code ReviewCode Review
Code Review
 
BugDay 2012 : The variety of Unit Testing #1
BugDay 2012 : The variety of Unit Testing #1BugDay 2012 : The variety of Unit Testing #1
BugDay 2012 : The variety of Unit Testing #1
 
A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26A Test Manifesto 2014.03.26
A Test Manifesto 2014.03.26
 
Introduction to Continuous Delivery
Introduction to Continuous DeliveryIntroduction to Continuous Delivery
Introduction to Continuous Delivery
 

Similar to Test-Driven Development (TDD) in Swift

Demise of test scripts rise of test ideas
Demise of test scripts rise of test ideasDemise of test scripts rise of test ideas
Demise of test scripts rise of test ideas
Richard Robinson
 
Project Onion unit test environment
Project Onion unit test environmentProject Onion unit test environment
Project Onion unit test environment
Abhinav Jha
 
Lessons Learned When Automating
Lessons Learned When AutomatingLessons Learned When Automating
Lessons Learned When Automating
Alan Richardson
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
Peter Kofler
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
wesovi
 
Unit testing
Unit testingUnit testing
Unit testing
PiXeL16
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
Xavi Hidalgo
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
Abhijeet Vaikar
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
Adam Doyle
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
Dharmendra Prasad
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Sahar Nofal
 
Test Automation
Test AutomationTest Automation
Test Automation
Rodrigo Paiva
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
Lars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests Effectively
Paul Boocock
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
Knoldus Inc.
 
Wso2con test-automation
Wso2con test-automationWso2con test-automation
Wso2con test-automation
krishantha_samaraweera
 
Path dependent-development (PyCon India)
Path dependent-development (PyCon India)Path dependent-development (PyCon India)
Path dependent-development (PyCon India)
ncoghlan_dev
 
Super fast end-to-end-tests
Super fast end-to-end-testsSuper fast end-to-end-tests
Super fast end-to-end-tests
Lars Thorup
 
Fast end-to-end-tests
Fast end-to-end-testsFast end-to-end-tests
Fast end-to-end-tests
Rikke Veng Petersen
 

Similar to Test-Driven Development (TDD) in Swift (20)

Demise of test scripts rise of test ideas
Demise of test scripts rise of test ideasDemise of test scripts rise of test ideas
Demise of test scripts rise of test ideas
 
Project Onion unit test environment
Project Onion unit test environmentProject Onion unit test environment
Project Onion unit test environment
 
Lessons Learned When Automating
Lessons Learned When AutomatingLessons Learned When Automating
Lessons Learned When Automating
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Writing Tests Effectively
Writing Tests EffectivelyWriting Tests Effectively
Writing Tests Effectively
 
Cypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
 
Wso2con test-automation
Wso2con test-automationWso2con test-automation
Wso2con test-automation
 
Path dependent-development (PyCon India)
Path dependent-development (PyCon India)Path dependent-development (PyCon India)
Path dependent-development (PyCon India)
 
Super fast end-to-end-tests
Super fast end-to-end-testsSuper fast end-to-end-tests
Super fast end-to-end-tests
 
Fast end-to-end-tests
Fast end-to-end-testsFast end-to-end-tests
Fast end-to-end-tests
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
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
 
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
Vlad Stirbu
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
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
FIDO Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
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
91mobiles
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
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
 
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
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
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
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
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
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 

Test-Driven Development (TDD) in Swift

  • 1. Making Software. Better. Simple solutions to big business problems. Test-Driven Development In Swift by @ameytavkar @javalnanda
  • 2. Why do we test?
  • 3. Why do we test? ● Confidence - Gain confidence in the system we are building. ● Verification - To verify what we create does what it’s supposed to do. ● Learning - Identify weak areas of the system.
  • 4. Testing can be done manually or can be automated.
  • 5. Why Automation? ● Faster Regression Tests - Automated tools run significantly faster than us. ● Easier Refactoring - Shortened feedback loops helps us to improve our design much easily ● Continuous Integration - Having automated tests makes integration painless and significantly faster.
  • 6. Should we write our tests before or after implementation?
  • 7. Why writing tests after implementation is bad? ● Laziness - Once the system is tested manually, writing unit tests seems like a extra effort. ● Lack of Discipline - Code written without considering testing rapidly becomes tightly coupled and makes it hard to refactor in later stages. ● Compromise - Tests are generally influenced by the written code instead of the actual user requirements.
  • 8. Why should we test first?
  • 9. Why should we test first? ● Loosely Coupled Code - We tend to make our modules independent which in turn helps in creating loosely coupled code. ● Verification - We write the tests keeping the requirements in mind. ● Confidence - We gain confidence that we won’t be breaking any functionality in the process of implementing new ones.
  • 12. High test coverage is not the end goal of TDD, it’s a side effect of it.
  • 15. Tic Tac Toe Requirements 1. A marker can be placed on any empty space of a 3×3 board. ○ Game engine should be able to create a 3x3 board on initialization ○ Game engine should be able to place a marker on a board ○ Game engine should not be able to place the marker on an already placed marker 2. Two Players can take turns marking the spaces on the board. ○ Game engine should have 2 players on initialization ○ On start player one takes the move ○ After move game engine should toggle player turns
  • 17. Common Pitfalls in TDD ● Not Testing Behaviors - Test behaviors not implementations ● Having Dependencies - Avoid tests that depend on each other ● Not Refactoring on Green - Don’t jump ahead to next tests without checking the need to refactor once you get a green for a test.
  • 18. Common Pitfalls in TDD (Cont.) ● Poor Readability - Never ignore the importance of naming the tests correctly. Tests are also executable requirement spec. Treat them well and try to name it relevant to the behaviour you are testing. ● Large Tests - Avoid testing more than one behaviour in a single unit test. ● Not Respecting Privacy - Don’t violate scope just because you are not able to test something. If it is hard to write the test, its a sign of code smell.
  • 19. What not to test? ● Private Methods - This is an implementation detail and the tests for the exposed methods should be sufficient enough to cover the private ones ● External Library/Framework - The framework should be tested by its own developer! ● UI Design - Constraints, Layouts should be part of UI Tests
  • 21. Best Practises ● Use a good architecture ● Use protocols to isolate class to test ● Write structured tests - Arrange, Act and Assert ● Don’t start with edge cases ● Always work on one test case at a time ● Avoid writing redundant tests
  • 22. How to test Controllers ● Move the non-UI specific logic code out of the viewcontrollers ● Use dependency injection to your advantage ● Use closures to your advantage
  • 23. How to Mock Dependencies using protocols? ● Find the method/behavior definition(s) on the object that you need to confirm interactions with ● Create your own protocol to duplicate the definition(s) ● Create a fake object that implements that the protocol ● Use the fake objects in your tests
  • 24. Tools that we recommend ● Unit Tests ○ Quick / Nimble ‐ https://github.com/Quick/Quick ‐ Helps in forcing the developer to write more english-like statements ● UI Automation ○ EarlGrey ○ https://github.com/google/EarlGrey ○ Synchronized UI Tests! ● Mocking ○ Cuckoo ‐ https://github.com/Brightify/Cuckoo ‐ Auto-generate your mocks in swift!
  • 26. Conclusions ● Automation Tests are our friends ● Testing before implementation forces us to think about design. ● TDD Mantra - RED -> GREEN -> REFACTOR -> REPEAT ● Test early, Test Often! ● TDD isn’t about tests, its about design ● We have loosely coupled and highly cohesive code by following TDD Mantra ● Gain Confidence in the system ● High Code coverage
  • 27. Thank You United Kingdom +44 203 603 7830 helloUK@equalexperts.com Equal Experts UK Ltd 30 Brock Street London NW1 3FG India +91 20 6607 7763 helloIndia@equalexperts.com Equal Experts India Private Ltd Office No. 4-C Cerebrum IT Park No. B3 Kumar City, Kalyani Nagar Pune, 411006 Canada +1 403 775 4861 helloCanada@equalexperts.com Equal Experts Devices Inc 205 - 279 Midpark way S.E. T2X 1M2 Calgary, Alberta Portugal +351 211 378 414 helloPortugal@equalexperts.com Equal Experts Portugal Avenida Dom João II, Nº35 Edificio Infante 11ºA 1990-083 Parque das Nações Lisboa – Portugal Thank You USA +1 866-943-9737 helloUSA@equalexperts.com Equal Experts Inc 1460 Broadway New York NY 10036   LinkedIn linkedin.com/company/equal-experts Twitter @EqualExperts Web www.equalexperts.com
  • 28. References 1. http://www.netobjectives.com/blogs/why-test-driven-development-really-isn%E2%80% 99t-test-first 2. https://8thlight.com/blog/uncle-bob/2014/04/30/When-tdd-does-not-work.html 3. https://vimeo.com/68375232 4. https://github.com/javalnanda/good-tdd-stuff 5. https://blog.eliperkins.me/mocks-in-swift-via-protocols/