SlideShare a Scribd company logo
Unit Testing
Brian Hu
Why Test
• Catch errors
• Help you write code
• Speed up your development
• Cover configurations
• Cover new co-workers
What is a unit test
• Tests ONE thing
• Single “unit” of functionality
• Small, fast, ISOLATED
Unit Tests don’t cover
• Performance
• UI interaction
• Whole system integration
Guidelines
• Testing should be automated and non-interactive
• Let your code JUST pass the test
• Remember to test boundary cases, but also remember that it’s
impossible to test every case
• Provide a random generator when it’s possible
• Keep testing at unit level
• Act as 3rd party class consumer
• Passed tests don’t promise the correctness of code
XCTest
Tutorial Project
http://is.gd/nDMTWU
Instruction
• We have 4 tests in this project: testValidateEmail,
testSubmit, testIsEmpty, testValidatePassword
• I’ll do the “testValidateEmail” step by step for you.
• I have written the tests of “testIsEmpty” and
“testSubmit” for you. Please implement the logic
by yourself.
• Please write the test and implement the logic for
the last test by yourself.
API you may need
#if DEBUG
[NSException raise:@“Invalid Email Exception”
format:@"email is invalid”];
#endif
Password requirement
• length between 6~12
• has at least 1 uppercase letter and 1 lowercase
letter

More Related Content

PDF
Extreme Programming - to the next-level
PPTX
Aistė Stikliutė - Testing in continuous delivery
PDF
Introduction to Automated Testing
PDF
Unit testing in PHP
PDF
Automated Performance Testing
PDF
Automated testing
PPTX
Bootstrapping Quality
PPTX
QA Automation testing online training
Extreme Programming - to the next-level
Aistė Stikliutė - Testing in continuous delivery
Introduction to Automated Testing
Unit testing in PHP
Automated Performance Testing
Automated testing
Bootstrapping Quality
QA Automation testing online training

What's hot (20)

PPTX
Testing activities in continuous integration and continuous delivery as an ex...
PDF
Testing activities in CI/CD as exploratory tester
PPTX
Value of Unit Testing
PDF
Fast end-to-end-tests
PPTX
Continuous Integration: Finding problems soonest
PPTX
How to write better tests with Test Driven Development
PDF
Becoming a better programmer - unit testing
PDF
Test-driven development with Node.js
PPT
Walking Skeleton
PPT
Unit Testing, TDD and the Walking Skeleton
PDF
How to get reviewers to block your changes
PPTX
Presentation delex
PPTX
Continuous delivery in practice (public)
PPTX
Writing Better Tests - Applying Clean-Code TDD at 99designs
PDF
Drulenium - Testing Made Easy
PDF
TDD done right - tests immutable to refactor
PPTX
Sustainable Automation Frameworks by Kelsey Shannahan
KEY
Driving application development through behavior driven development
PPTX
Agile Testing in Enterprise: Way to transform - SQA Days 2014
PPTX
Selenium done right
Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in CI/CD as exploratory tester
Value of Unit Testing
Fast end-to-end-tests
Continuous Integration: Finding problems soonest
How to write better tests with Test Driven Development
Becoming a better programmer - unit testing
Test-driven development with Node.js
Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
How to get reviewers to block your changes
Presentation delex
Continuous delivery in practice (public)
Writing Better Tests - Applying Clean-Code TDD at 99designs
Drulenium - Testing Made Easy
TDD done right - tests immutable to refactor
Sustainable Automation Frameworks by Kelsey Shannahan
Driving application development through behavior driven development
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Selenium done right
Ad

Similar to Unit testing (20)

PDF
Automated Testing on iOS
PDF
Unit testing in xcode 8 with swift
PDF
A Comprehensive Guide to Efficiently Writing and Implementing iOS Unit Tests.pdf
PPTX
Unit test
PDF
Unit Tesing in iOS
PPS
Unit testing_pps
PPT
Nguyenvandungb seminar
PPT
Unit Testing in iOS
PDF
Testing (eng)
PDF
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
PDF
Beginning iOS unit testing
PDF
XCTest_ A Complete Comprehensive Guide.pdf
PPTX
Unit Testing in Java
PPT
Intro to junit
PPTX
Java Unit Testing
PPTX
RIA 05 - Unit Testing by Ajinkya Prabhune
PPS
Unit Testing
PDF
Swift testing ftw
PPTX
Junit4&testng presentation
PPTX
Getting Started with XCTest and XCUITest for iOS App Testing
Automated Testing on iOS
Unit testing in xcode 8 with swift
A Comprehensive Guide to Efficiently Writing and Implementing iOS Unit Tests.pdf
Unit test
Unit Tesing in iOS
Unit testing_pps
Nguyenvandungb seminar
Unit Testing in iOS
Testing (eng)
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Beginning iOS unit testing
XCTest_ A Complete Comprehensive Guide.pdf
Unit Testing in Java
Intro to junit
Java Unit Testing
RIA 05 - Unit Testing by Ajinkya Prabhune
Unit Testing
Swift testing ftw
Junit4&testng presentation
Getting Started with XCTest and XCUITest for iOS App Testing
Ad

Recently uploaded (20)

PDF
Mushroom cultivation and it's methods.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
August Patch Tuesday
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPT
Teaching material agriculture food technology
PDF
A comparative study of natural language inference in Swahili using monolingua...
Mushroom cultivation and it's methods.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
August Patch Tuesday
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Getting Started with Data Integration: FME Form 101
Digital-Transformation-Roadmap-for-Companies.pptx
1. Introduction to Computer Programming.pptx
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Tartificialntelligence_presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Teaching material agriculture food technology
A comparative study of natural language inference in Swahili using monolingua...

Unit testing

  • 2. Why Test • Catch errors • Help you write code • Speed up your development • Cover configurations • Cover new co-workers
  • 3. What is a unit test • Tests ONE thing • Single “unit” of functionality • Small, fast, ISOLATED
  • 4. Unit Tests don’t cover • Performance • UI interaction • Whole system integration
  • 5. Guidelines • Testing should be automated and non-interactive • Let your code JUST pass the test • Remember to test boundary cases, but also remember that it’s impossible to test every case • Provide a random generator when it’s possible • Keep testing at unit level • Act as 3rd party class consumer • Passed tests don’t promise the correctness of code
  • 8. Instruction • We have 4 tests in this project: testValidateEmail, testSubmit, testIsEmpty, testValidatePassword • I’ll do the “testValidateEmail” step by step for you. • I have written the tests of “testIsEmpty” and “testSubmit” for you. Please implement the logic by yourself. • Please write the test and implement the logic for the last test by yourself.
  • 9. API you may need #if DEBUG [NSException raise:@“Invalid Email Exception” format:@"email is invalid”]; #endif
  • 10. Password requirement • length between 6~12 • has at least 1 uppercase letter and 1 lowercase letter