SlideShare a Scribd company logo
Unit Test
Đức Trần
Unit Test
Why Testing?
Beginning Unit Test
Asynchronous Testing
Performance Testing
Why Testing?
Find bug
Clear requirement
Maintenance
How?
1. Code
2. Add Tests
3. Modify code for passing Tests
Vs
1. Write Tests
2. Write code that pass Tests (Test-Driven Development)
Beginning Unit Test
Beginning Unit Test
XCTest
Test Target
Running Test
Viewing Result
XCTest
Subclass XCTestCase
Implement Test method
(Beginning with “test”)
- (void)testMyMethodWorks
Use Assertion (Macro) APIs to report failures
- XCTAssertEqual(value, expectValue);
Test Target
Test Target:
- Test code
- Resources
Automatically included in new project
Existing projects can add test targets
Running Test
Command+U
Buttons in source editor sidebar
Buttons in Test Navigator
Viewing Result
Test Navigator
Viewing Result
Test Navigator
Issue Navigator
Viewing Result
Test Navigator
Issue Navigator
Source Editor
Viewing Result
Test Navigator
Issue Navigator
Source Editor
Test Report
Demo
Adding Test Case
Prepare “fake” data
Create Model
Create Service
Write Test Case
Implement Method
Write code to implement methods.
Check if test cases are passed
Asynchronous Testing
Asynchronous Testing
Create Expectation Object:
- XCTestExpectation *expectation = [self expectationWithDescription:@"Load Data"];
XCTestCase waits for Expectations to “Fullfill”
- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(nullable
XCWaitCompletionHandler)handler;
Handle when finishing asynchronous tasks:
- [expectation fulfill];
Demo
Asynchronous Testing
Add Asynchronous method
Write Test case
Implement method
Write code to implement methods.
Check if test cases are passed
Performance Testing
Performance Testing
How to measure app performance?
How to find which part causes performance problem?
=> Performance Testing.
Measuring Performance
Test code block:
- (void)measureBlock:(void (^)(void))block;
Runs code block 10 time
Measures time
Results show in Xcode
Performance Testing
Setting Baselines
Setting Standard Deviation (STDDEV)
Setting Baselines
Baselines is Average run time
Detect Regressions:
- Fail if (Baselines Average)>0.1 seconds and >10%
Baselines are stored in sources
Baselines are per-device configuration:
- Device model, CPU, OS
Setting Baseline
No Baseline Set Baseline
Setting Baselines
Normal case (Baseline 1s) Error Case (Baseline 1s)
Setting Baseline
Baselines are not enough
Setting Standard Deviation (STDDEV)
Fail if (STDDEV)>0.1 seconds and >10%
Standard Deviation
Why STDDEV too big?
- File I/O, Network I/O?
- Initialization?
- Does it do the same work each time it's called?
- System busy?
Profiling Test
Investigate functions’ performance
Demo
Performance Testing
Performance Test
Summary
Why Testing?
Beginning Unit Test
Asynchronous Testing
Performance Testing
Reference
WWDC’s video: https://developer.apple.com/videos/play/wwdc2014/414/
Unit Test Sample:
https://developer.apple.com/library/mac/samplecode/UnitTests/History/History.
html#//apple_ref/doc/uid/DTS40011742-RevisionHistory-DontLinkElementID_1
Udacity Course: https://www.udacity.com/course/viewer#!/c-cs212/l-
48688918/m-48276959
Demo Source: https://www.dropbox.com/s/mhjpllmxugyf02c/UnitTest.zip?dl=1
QA?
1. How to implement UITest?
- Checkout apple’s Sample app:
https://developer.apple.com/library/mac/samplecode/UnitTests/History/Hist
ory.html#//apple_ref/doc/uid/DTS40011742-RevisionHistory-
DontLinkElementID_1
- Checkout this WWDC session:
https://developer.apple.com/videos/play/wwdc2015/406/
Assignment
Write a sample app using UnitTest
- Which test cases should we have to cover?
Thanks for watching!

More Related Content

PPTX
Unit Testing And Mocking
PPTX
Unit Testing Concepts and Best Practices
PPTX
Unit testing
PPT
TESTING LIFE CYCLE PPT
PDF
Unit testing best practices
PDF
An introduction to unit testing
PDF
Unit testing with JUnit
PPTX
Automation Testing
Unit Testing And Mocking
Unit Testing Concepts and Best Practices
Unit testing
TESTING LIFE CYCLE PPT
Unit testing best practices
An introduction to unit testing
Unit testing with JUnit
Automation Testing

What's hot (20)

PPTX
Unit tests & TDD
PPTX
An Introduction to Unit Testing
PDF
Unit and integration Testing
PPTX
Test automation within a scrum process
PDF
Mutation Testing
PPT
Test Automation Framework Designs
PPTX
Unit Testing
PPSX
PPT
Software Testing 101
PPTX
Understanding Unit Testing
PPTX
Unit Tests And Automated Testing
PPT
Manual testing concepts course 1
PPT
Test automation process
PPTX
Automation Tools Overview
PPTX
UNIT TESTING PPT
PPS
Unit Testing
PPSX
Principles of Software testing
DOCX
Realtime selenium interview questions
PPTX
Unit testing & TDD concepts with best practice guidelines.
PPTX
Mocking with Mockito
Unit tests & TDD
An Introduction to Unit Testing
Unit and integration Testing
Test automation within a scrum process
Mutation Testing
Test Automation Framework Designs
Unit Testing
Software Testing 101
Understanding Unit Testing
Unit Tests And Automated Testing
Manual testing concepts course 1
Test automation process
Automation Tools Overview
UNIT TESTING PPT
Unit Testing
Principles of Software testing
Realtime selenium interview questions
Unit testing & TDD concepts with best practice guidelines.
Mocking with Mockito
Ad

Viewers also liked (12)

PDF
Introduction of unit test to management
PDF
Unit test in a nutshell
PDF
TDD Dojo - Test Driven Development Coding Dojo
PPTX
Tdd & unit test
PDF
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
PPTX
Unbox yourself Into Testing
PDF
Inverting The Testing Pyramid
PPTX
Testing web application
PDF
Agile Testing Framework - The Art of Automated Testing
PDF
Unit Test + Functional Programming = Love
PDF
Web application testing with Selenium
PDF
Workshop unit test
Introduction of unit test to management
Unit test in a nutshell
TDD Dojo - Test Driven Development Coding Dojo
Tdd & unit test
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
Unbox yourself Into Testing
Inverting The Testing Pyramid
Testing web application
Agile Testing Framework - The Art of Automated Testing
Unit Test + Functional Programming = Love
Web application testing with Selenium
Workshop unit test
Ad

Similar to Unit test (20)

PPTX
Test driven development in .Net - 2010 + Eclipse
PPT
12 Rational Solo Pruebas 2009
PPS
Why Unit Testingl
PPS
Why Unit Testingl
PPS
Why unit testingl
PDF
DSR Testing (Part 1)
PPT
Unit testing
PPTX
TDD Best Practices
PPTX
Testing 101
PPTX
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
PPTX
Full Testing Experience - Visual Studio and TFS 2010
PPT
Unit testing php-unit - phing - selenium_v2
PPT
Automated Software Testing Framework Training by Quontra Solutions
PDF
SELJE_Database_Unit_Testing_Slides.pdf
PPT
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
PPTX
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
DOCX
Chapter 10 Testing and Quality Assurance1Unders.docx
PDF
TDD Workshop UTN 2012
PPTX
utPLSQL: Unit Testing for Oracle PL/SQL
PPT
Paper Ps
Test driven development in .Net - 2010 + Eclipse
12 Rational Solo Pruebas 2009
Why Unit Testingl
Why Unit Testingl
Why unit testingl
DSR Testing (Part 1)
Unit testing
TDD Best Practices
Testing 101
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Full Testing Experience - Visual Studio and TFS 2010
Unit testing php-unit - phing - selenium_v2
Automated Software Testing Framework Training by Quontra Solutions
SELJE_Database_Unit_Testing_Slides.pdf
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Chapter 10 Testing and Quality Assurance1Unders.docx
TDD Workshop UTN 2012
utPLSQL: Unit Testing for Oracle PL/SQL
Paper Ps

Unit test