SlideShare a Scribd company logo
1 of 43
Download to read offline
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

What's hot

Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration TestingDavid Berliner
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBaskar K
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 
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 FrameworkHumberto Marchezi
 
Agile Testing and Test Automation
Agile Testing and Test AutomationAgile Testing and Test Automation
Agile Testing and Test AutomationNaveen Kumar Singh
 
Integration testing
Integration testingIntegration testing
Integration testingqueen jemila
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Edureka!
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 

What's hot (20)

Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
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
 
Junit
JunitJunit
Junit
 
Agile Testing and Test Automation
Agile Testing and Test AutomationAgile Testing and Test Automation
Agile Testing and Test Automation
 
Integration testing
Integration testingIntegration testing
Integration testing
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Unit testing with java
Unit testing with javaUnit testing with java
Unit testing with java
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Testing
TestingTesting
Testing
 
Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium Data driven Automation Framework with Selenium
Data driven Automation Framework with Selenium
 
TestNG
TestNGTestNG
TestNG
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 

Viewers also liked

Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to managementweili_at_slideshare
 
TDD Dojo - Test Driven Development Coding Dojo
TDD Dojo - Test Driven Development Coding DojoTDD Dojo - Test Driven Development Coding Dojo
TDD Dojo - Test Driven Development Coding DojoRoberto Bettazzoni
 
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About ItWhy Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About ItHoward Deiner
 
Unbox yourself Into Testing
Unbox yourself Into TestingUnbox yourself Into Testing
Unbox yourself Into Testingvodqancr
 
Inverting The Testing Pyramid
Inverting The Testing PyramidInverting The Testing Pyramid
Inverting The Testing PyramidNaresh Jain
 
Agile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated TestingAgile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated TestingDimitri Ponomareff
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with SeleniumKerry Buckley
 

Viewers also liked (11)

Introduction of unit test to management
Introduction of unit test to managementIntroduction of unit test to management
Introduction of unit test to management
 
Unit test in a nutshell
Unit test in a nutshellUnit test in a nutshell
Unit test in a nutshell
 
TDD Dojo - Test Driven Development Coding Dojo
TDD Dojo - Test Driven Development Coding DojoTDD Dojo - Test Driven Development Coding Dojo
TDD Dojo - Test Driven Development Coding Dojo
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About ItWhy Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
Why Johnny Can't Unit Test His Legacy Code - And What You Can Do About It
 
Unbox yourself Into Testing
Unbox yourself Into TestingUnbox yourself Into Testing
Unbox yourself Into Testing
 
Inverting The Testing Pyramid
Inverting The Testing PyramidInverting The Testing Pyramid
Inverting The Testing Pyramid
 
Testing web application
Testing web applicationTesting web application
Testing web application
 
Agile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated TestingAgile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated Testing
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 

Similar to Unit test

Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
12 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 200912 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 2009Pepe
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databasesAlessandro Alpi
 
Full Testing Experience - Visual Studio and TFS 2010
 Full Testing Experience - Visual Studio and TFS 2010 Full Testing Experience - Visual Studio and TFS 2010
Full Testing Experience - Visual Studio and TFS 2010Ed Blankenship
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsQuontra Solutions
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfEric Selje
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis Engineering Software Lab
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Comunidade NetPonto
 
Chapter 10 Testing and Quality Assurance1Unders.docx
Chapter 10 Testing and Quality Assurance1Unders.docxChapter 10 Testing and Quality Assurance1Unders.docx
Chapter 10 Testing and Quality Assurance1Unders.docxketurahhazelhurst
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLSteven Feuerstein
 

Similar to Unit test (20)

Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
12 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 200912 Rational Solo Pruebas 2009
12 Rational Solo Pruebas 2009
 
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
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Unit testing
Unit testingUnit testing
Unit testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Testing 101
Testing 101Testing 101
Testing 101
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Full Testing Experience - Visual Studio and TFS 2010
 Full Testing Experience - Visual Studio and TFS 2010 Full Testing Experience - Visual Studio and TFS 2010
Full Testing Experience - Visual Studio and TFS 2010
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Automated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra SolutionsAutomated Software Testing Framework Training by Quontra Solutions
Automated Software Testing Framework Training by Quontra Solutions
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
Chapter 10 Testing and Quality Assurance1Unders.docx
Chapter 10 Testing and Quality Assurance1Unders.docxChapter 10 Testing and Quality Assurance1Unders.docx
Chapter 10 Testing and Quality Assurance1Unders.docx
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQL
 

Unit test