Upload
others
View
22
Download
0
Embed Size (px)
Citation preview
AUTOMATED TESTING ON IOS
AGENDAFundamentals of automated tests
Different Types of Tests
Unit Tests
Integration Tests
UI Tests
Demo
FUNDAMENTALS OF AUTOMATED TESTS
FUNDAMENTALS
Write code to specify & verify behavior of application
When I attempt to log inAnd the provided password is incorrectI expect to see an error message
What is being tested?
How is it being tested?
What is the expected result?
FUNDAMENTALSWithout tests you:
1. Change code
2. Restart App
3. Set up required state & navigate to part of app you are testing
4. Find out the behavior is still wrong, start over at 1.
⌘+R → 🕐🕑🕒
FUNDAMENTALS
An application with good test coverage can be validated
almost entirely in a few seconds
⌘+U → ✅
You can even run this on a CI Server!
CONTINOUS INTEGRATION SERVERS
JenkinsTravis-CI Circle-CI
Run automated tests upon every push to repository - send notifications to you and team members when tests break!
SUMMARY
When I attempt to log inAnd the provided password is incorrectI expect to see an error message
Tests describe your application’s behavior to other developers and product owners! They allow you to automatically verify correctness of application!
DIFFERENT TYPES OF TESTS
DIFFERENT TYPES OF TESTS
Unit Tests - Verify the behavior of one individual unit of work
Integration Tests - Test entire features, e.g. login while connecting to a
backend server
UI Tests - Interact with your application through the regular UI elements,
specific form of integration test
Which code is broken?
Which feature is broken?
Can the user interact with UI as expected?
UNIT TESTS
FEATURES OF A UNIT TEST
Runs isolated from any other test, sets up its entire environment
Only tests a single unit of code - all this code’s dependencies need to be mocked out (details later)
HOW TO WRITE A UNIT TEST
Arrange set up the state that the test needs to run - e.g. create
the object you want to test
Act interact with your code - e.g. call a method on the created
object
Assert verify the result - e.g. check that the state of the object
changed as expected
HOW TO VERIFY UNIT TESTS
Return Value you call a function/method and assert on the
return value
State Change you call a method and assert that the state of
the object changed
Interaction you call a method and make sure that the object
calls another object
HOW TO ISOLATE UNIT TESTS
Stubs return predefined results for method calls/properties
Mocks are used to verify that a method has been called on a
given object
Fakes behave similar to the real object but take shortcuts in implementation (complex Stubs)
INTEGRATION TESTS
FEATURES OF AN INTEGRATION TEST
Less strict than a Unit Test, can test a larger portion of functionality
Is allowed to depend on outside resources, e.g. a database or a web service
Useful for testing a feature in its real environment
Higher chance of “false positives”
UI TESTING
FEATURES OF AN UI TEST
Specific form of integration test that tests your app entirely
through the UI
Xcode 7 provides support for recording UI tests
SUMMARY
SUMMARY
There are two broad categories of automated tests, Unit Tests
and Integration Tests
Automated tests allow us to verify applications fast and reliably
Automated tests inform us about breaking changes to existing
features
ADDITIONAL RESOURCES
ADDITIONAL RESOURCES
Book by Roy Osherove: The Art of Unit Testing
Blog Post: iOS Testing in 2015
iOS Unit Testing Blog
Blog Post: Mocking in Swift
LIVE CODING: NUMBER GUESSING GAME
NUMBER GUESSING GAME1. Computer guesses a number within a specified range
2. You attempt to guess number
3. Computer tells you whether you were correct or whether
number was too low or too high
4. You repeat step 2.-4. until you guessed the number
successfully