26

AUTOMATED TESTING ON IOS · 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

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: AUTOMATED TESTING ON IOS · 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
Page 2: AUTOMATED TESTING ON IOS · 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

AUTOMATED TESTING ON IOS

Page 3: AUTOMATED TESTING ON IOS · 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

AGENDAFundamentals of automated tests

Different Types of Tests

Unit Tests

Integration Tests

UI Tests

Demo

Page 4: AUTOMATED TESTING ON IOS · 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

FUNDAMENTALS OF AUTOMATED TESTS

Page 5: AUTOMATED TESTING ON IOS · 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

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?

Page 6: AUTOMATED TESTING ON IOS · 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

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 → 🕐🕑🕒

Page 7: AUTOMATED TESTING ON IOS · 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

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!

Page 8: AUTOMATED TESTING ON IOS · 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

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!

Page 9: AUTOMATED TESTING ON IOS · 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

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!

Page 10: AUTOMATED TESTING ON IOS · 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

DIFFERENT TYPES OF TESTS

Page 11: AUTOMATED TESTING ON IOS · 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

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?

Page 12: AUTOMATED TESTING ON IOS · 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

UNIT TESTS

Page 13: AUTOMATED TESTING ON IOS · 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

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)

Page 14: AUTOMATED TESTING ON IOS · 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

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

Page 15: AUTOMATED TESTING ON IOS · 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

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

Page 16: AUTOMATED TESTING ON IOS · 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

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)

Page 17: AUTOMATED TESTING ON IOS · 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

INTEGRATION TESTS

Page 18: AUTOMATED TESTING ON IOS · 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

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”

Page 19: AUTOMATED TESTING ON IOS · 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

UI TESTING

Page 20: AUTOMATED TESTING ON IOS · 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

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

Page 21: AUTOMATED TESTING ON IOS · 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

SUMMARY

Page 22: AUTOMATED TESTING ON IOS · 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

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

Page 23: AUTOMATED TESTING ON IOS · 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

ADDITIONAL RESOURCES

Page 24: AUTOMATED TESTING ON IOS · 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

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

Page 25: AUTOMATED TESTING ON IOS · 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

LIVE CODING: NUMBER GUESSING GAME

Page 26: AUTOMATED TESTING ON IOS · 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

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