414 testing in xcode df - apple inc....getting started asynchronous testing performance testing....

180
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Testing in Xcode 6 Session 414 Brooke Callahan Xcode Software Engineer Tools Wil Turner Xcode Software Engineer

Upload: others

Post on 04-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Testing in Xcode 6

Session 414 Brooke Callahan Xcode Software Engineer

Tools

!

Wil Turner Xcode Software Engineer

Page 2: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What We’ll Cover

Page 3: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What We’ll Cover

Benefits of testing

Page 4: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What We’ll Cover

Benefits of testing

Getting started

Page 5: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What We’ll Cover

Benefits of testing

Getting started

Asynchronous testing

Page 6: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What We’ll Cover

Benefits of testing

Getting started

Asynchronous testing

Performance testing

Page 7: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Overview

Page 8: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

MotivationWhy test?

Page 9: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

MotivationWhy test?

Find bugs

Page 10: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

MotivationWhy test?

Find bugs

Codify requirements

Page 11: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Page 12: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Page 13: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Verify that tests pass

Page 14: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Verify that tests pass

Or

Page 15: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Verify that tests pass

Or

Write tests

Page 16: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Verify that tests pass

Or

Write tests

Write code that passes the tests

Page 17: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowGetting started

Add tests

Verify that tests pass

Or

Write tests

Write code that passes the tests

AKA “Test-Driven Development”

Page 18: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowContinuous Integration

Page 19: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowContinuous Integration

Coding

Page 20: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowContinuous Integration

Bug Introduced

Page 21: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

WorkflowContinuous Integration

Page 22: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Getting Started

Page 23: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Page 24: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Subclass XCTestCase

Page 25: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Subclass XCTestCase

Implement test methods

Page 26: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Subclass XCTestCase

Implement test methods• - (void)testThatMyFunctionWorks

Page 27: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Subclass XCTestCase

Implement test methods• - (void)testThatMyFunctionWorks

Use assertion APIs to report failures

Page 28: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

XCTestXcode’s framework for testing

Subclass XCTestCase

Implement test methods• - (void)testThatMyFunctionWorks

Use assertion APIs to report failures• XCTAssertEqual(value, expectedValue);

Page 29: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Page 30: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Tests targets build bundles

Page 31: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Tests targets build bundles• Test code

Page 32: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Tests targets build bundles• Test code

• Resources

Page 33: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Tests targets build bundles• Test code

• Resources

Automatically included in new projects

Page 34: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Targets

Tests targets build bundles• Test code

• Resources

Automatically included in new projects

Existing projects can add test targets

Page 35: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Page 36: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process

Page 37: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process• Injected into your app, or

Page 38: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process• Injected into your app, or

• Hosting process provided by Xcode

Page 39: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process• Injected into your app, or

• Hosting process provided by Xcode

Resources for tests are not in the main bundle

Page 40: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process• Injected into your app, or

• Hosting process provided by Xcode

Resources for tests are not in the main bundle• Don’t use +[NSBundle mainBundle]

Page 41: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test HostingHow tests are run

Test bundles are executed by a host process• Injected into your app, or

• Hosting process provided by Xcode

Resources for tests are not in the main bundle• Don’t use +[NSBundle mainBundle]

• Use +[NSBundle bundleForClass:[MyTest class]]

Page 42: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationRunning tests

Page 43: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationRunning tests

Command-U

Page 44: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationRunning tests

Command-U

Buttons in the Source Editor side bar

Page 45: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationRunning tests

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

Page 46: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

xcodebuild

Xcode IntegrationRunning tests

Page 47: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

xcodebuild xcodebuild test \

Xcode IntegrationRunning tests

Page 48: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

xcodebuild xcodebuild test \ -project ~/Documents/MyApp.xcodeproj \

Xcode IntegrationRunning tests

Page 49: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

xcodebuild xcodebuild test \ -project ~/Documents/MyApp.xcodeproj \ -scheme MyApp \

Xcode IntegrationRunning tests

Page 50: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Command-U

Buttons in the Source Editor side bar

Buttons in the Test Navigator

xcodebuild xcodebuild test \ -project ~/Documents/MyApp.xcodeproj \ -scheme MyApp \ -destination 'platform=iOS,name=iPhone'

Xcode IntegrationRunning tests

Page 51: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationViewing results

Test Navigator

Page 52: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Test Navigator

Issue Navigator

Xcode IntegrationViewing results

Page 53: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationViewing results

Test Navigator

Issue Navigator

Source Editor side bar

Page 54: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Xcode IntegrationViewing results

Test Navigator

Issue Navigator

Source Editor side bar

Test Reports

Page 55: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

DemoAdding tests to an existing project

Page 56: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

What’s NewAPIs and tools

Page 57: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing with Xcode 6

Page 58: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing with Xcode 6

Compatibility improvements

Page 59: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing with Xcode 6

Compatibility improvements

Instruments integration

Page 60: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing with Xcode 6

Compatibility improvements

Instruments integration

New APIs

Page 61: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Compatibility ImprovementsXCTest on older iOS versions

Page 62: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Compatibility ImprovementsXCTest on older iOS versions

Originally part of iOS

Page 63: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Compatibility ImprovementsXCTest on older iOS versions

Originally part of iOS

Now ships with Xcode

Page 64: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Compatibility ImprovementsXCTest on older iOS versions

Originally part of iOS

Now ships with Xcode

New XCTest features work with older iOS versions

Page 65: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Compatibility ImprovementsXCTest on older iOS versions

Originally part of iOS

Now ships with Xcode

New XCTest features work with older iOS versions

iOS 6 and later

Page 66: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Page 67: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

Page 68: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Page 69: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)

Page 70: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)• Edit > Refactor > Convert to XCTest

Page 71: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)• Edit > Refactor > Convert to XCTest

• Some settings not in UI

Page 72: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)• Edit > Refactor > Convert to XCTest

• Some settings not in UI

Alternatively

Page 73: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)• Edit > Refactor > Convert to XCTest

• Some settings not in UI

Alternatively• Create a new test target

Page 74: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

OCUnit

Deprecated in Xcode 5.1

New features are only in XCTest

Use Migrator (recommended)• Edit > Refactor > Convert to XCTest

• Some settings not in UI

Alternatively• Create a new test target

• Move tests manually

Page 75: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

Page 76: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous

Page 77: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous• Block invocations

Page 78: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous• Block invocations

• Delegate callbacks

Page 79: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous• Block invocations

• Delegate callbacks

• Network requests

Page 80: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous• Block invocations

• Delegate callbacks

• Network requests

• Background processing

Page 81: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous Testing

More and more APIs are asynchronous• Block invocations

• Delegate callbacks

• Network requests

• Background processing

Unit tests run synchronously

Page 82: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingNew APIs in XCTest

Page 83: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingNew APIs in XCTest

“Expectation” objects describe expected events- (XCTestExpectation *)expectationWithDescription:(NSString *)description;

Page 84: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingNew APIs in XCTest

“Expectation” objects describe expected events- (XCTestExpectation *)expectationWithDescription:(NSString *)description;

XCTestCase waits for expectations to “fulfill”

Page 85: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingNew APIs in XCTest

“Expectation” objects describe expected events- (XCTestExpectation *)expectationWithDescription:(NSString *)description;

XCTestCase waits for expectations to “fulfill”- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(XCWaitCompletionHandler)handlerOrNil;

Page 86: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

Page 87: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{

Page 88: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

Page 89: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

UIDocument *doc = …;

[doc openWithCompletionHandler:^(BOOL success) {

Page 90: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

UIDocument *doc = …;

[doc openWithCompletionHandler:^(BOOL success) {

}];

Page 91: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

UIDocument *doc = …;

[doc openWithCompletionHandler:^(BOOL success) {

}];

[self waitForExpectationsWithTimeout:5.0 handler:nil];}

Page 92: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

UIDocument *doc = …;

[doc openWithCompletionHandler:^(BOOL success) {

}];

[self waitForExpectationsWithTimeout:5.0 handler:nil];}

XCTAssert(success); ! [expectation fulfill];

Page 93: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Asynchronous TestingExample

- (void)testDocumentOpening{ XCTestExpectation *expectation = [self expectationWithDescription:@“open doc”];

UIDocument *doc = …;

[doc openWithCompletionHandler:^(BOOL success) {

}];

[self waitForExpectationsWithTimeout:5.0 handler:nil];}

XCTAssert(success); ! [expectation fulfill];

Page 94: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

DemoWriting an asynchronous test

Page 95: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Brooke Callahan Xcode Software Engineer

Page 96: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Code changes can introduce performance regressions

Page 97: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Code changes can introduce performance regressions

Catching these regressions is difficult

Page 98: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Code changes can introduce performance regressions

Catching these regressions is difficult

Performance testing automates this

Page 99: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Overview

New APIs to measure performance

Page 100: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Overview

New APIs to measure performance

New UI to interpret results

Page 101: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Overview

New APIs to measure performance

New UI to interpret results

Profiling tests with Instruments

Page 102: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceNew API in XCTestCase

- (void)measureBlock:(void (^)(void))block;

Takes a block of code and runs it 10 times

Page 103: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceNew API in XCTestCase

- (void)measureBlock:(void (^)(void))block;

Takes a block of code and runs it 10 times

Measures time

Page 104: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceNew API in XCTestCase

- (void)measureBlock:(void (^)(void))block;

Takes a block of code and runs it 10 times

Measures time

Results show up in Xcode

Page 105: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceExample

- (void)testUseFileHandlePerformance { !

!

!

!

!

!

!

!

!

}

Page 106: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceExample

- (void)testUseFileHandlePerformance { [self measureBlock:^{ !

!

!

!

!

!

}]; }

Page 107: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceExample

- (void)testUseFileHandlePerformance { [self measureBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); !

UseFileHandle(fileHandle); [fileHandle closeFile]; }]; }

Page 108: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Profiling TestsInstruments integration

Profile individual tests • Source Editor context menu

• Test Navigator context menu

Page 109: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Profiling TestsInstruments integration

Profile individual tests • Source Editor context menu

• Test Navigator context menu

New Command in Product menu • Perform Action -> Profile “My App Tests”

Page 110: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Profiling TestsBuilding for Profiling

Page 111: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Profiling TestsBuilding for Profiling

Uses settings from Scheme Profile Action

Page 112: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Profiling TestsBuilding for Profiling

Uses settings from Scheme Profile Action

Behavior may be different when Profiling • Test builds for Debug

• Profile builds for Release

Page 113: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

DemoPerformance testing

Page 114: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceWrap-Up

Call -measureBlock: to detect performance regressions

Page 115: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceWrap-Up

Call -measureBlock: to detect performance regressions

View results in Source Editor and Test Report

Page 116: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PerformanceWrap-Up

Call -measureBlock: to detect performance regressions

View results in Source Editor and Test Report

Profile tests with Instruments

Page 117: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Setting Baselines

Page 118: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Setting Baselines

Standard Deviation

Page 119: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance Testing

Setting Baselines

Standard Deviation

Measuring precisely

Page 120: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

Baseline is the Average from a previous run

Page 121: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

Baseline is the Average from a previous run

Set Baseline Average to detect regressions • Fail if >10% increase from Baseline Average

• Regressions less than 0.1 seconds are ignored

Page 122: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

Baseline is the Average from a previous run

Set Baseline Average to detect regressions • Fail if >10% increase from Baseline Average

• Regressions less than 0.1 seconds are ignored

Baselines are stored in source

Page 123: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

Baseline is the Average from a previous run

Set Baseline Average to detect regressions • Fail if >10% increase from Baseline Average

• Regressions less than 0.1 seconds are ignored

Baselines are stored in source

Baselines are per-device configuration • Includes device model, CPU, and OS

Page 124: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Setting Baselines

Source Editor Annotations • No Baseline

Page 125: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Setting Baselines

Performance Result Popover • Source Editor

• Test Report

Shows values offset from average

Page 126: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Setting Baselines

Performance Result Popover • Source Editor

• Test Report

Set Baseline Average

Page 127: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Setting Baselines

Performance Result Popover • Source Editor

• Test Report

Edit Baseline and STDDEV

Page 128: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Setting Baselines

Performance Result Popover • Source Editor

• Test Report

Edit Baseline and STDDEV

Page 129: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

Source Editor annotations • Has Baseline: Passed

Page 130: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

Source Editor annotations • Has Baseline: Failed

Page 131: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

Test Report

Page 132: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

Test Log

Page 133: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Average: 1 second

Page 134: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Average: 1 second

Page 135: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Average: 1.5 seconds

Page 136: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Baseline Average

Fail if (Average–Baseline Average) is more than 10% of Baseline Average

Ignore if (Average–Baseline Average) less than 0.1 seconds

Page 137: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Is Average Enough?

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Average: 1 second

Page 138: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Is Average Enough?Problem?

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Average: 1 second

Page 139: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting VarianceStandard deviation

Average doesn’t tell the whole story

Page 140: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting VarianceStandard deviation

Average doesn’t tell the whole story

Standard deviation indicates spread of measurements

Page 141: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Variance

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Standard Deviation: 6%Average: 1 second

Page 142: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting VarianceProblem?

0

0.5

1

1.5

2

0 2.25 4.5 6.75 9

Standard Deviation: 40%Average: 1 second

Page 143: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Standard Deviation (STDDEV)

Fail if STDDEV is more than 10% of Average (adjustable)

Page 144: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Using Standard Deviation (STDDEV)

Fail if STDDEV is more than 10% of Average (adjustable)

Ignore if STDDEV is less than 0.1 seconds

Page 145: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Excessive STDDEV

Block being measured

Page 146: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Excessive STDDEV

Block being measured• Does file I/O or network I/O

Page 147: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Excessive STDDEV

Block being measured• Does file I/O or network I/O

• Doesn’t do the same work each time it’s called

Page 148: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Excessive STDDEV

Block being measured• Does file I/O or network I/O

• Doesn’t do the same work each time it’s called

System is busy with other processes

Page 149: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

1. If test has no Baseline Average, done

Page 150: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

1. If test has no Baseline Average, done

2. If STDDEV >0.1 seconds and >10%, fail

Page 151: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

1. If test has no Baseline Average, done

2. If STDDEV >0.1 seconds and >10%, fail

3. If (Average–Baseline Average) >0.1 seconds and >10%, fail

Page 152: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Detecting Regressions

1. If test has no Baseline Average, done

2. If STDDEV >0.1 seconds and >10%, fail

3. If (Average–Baseline Average) >0.1 seconds and >10%, fail

4. Else, pass

Page 153: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring Precisely

Only measure code you think that’s important to you

Page 154: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { [self measureBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); !

UseFileHandle(fileHandle); [fileHandle closeFile]; }]; }

Page 155: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); [self measureBlock:^{ UseFileHandle(fileHandle); [fileHandle closeFile]; }]; }

Page 156: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); [self measureBlock:^{ !

UseFileHandle(fileHandle); }]; !

[fileHandle closeFile]; }

Page 157: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)measureMetrics:(NSArray *)metrics automaticallyStartMeasuring:(BOOL)automaticallyStartMeasuring withBlock:(void (^)(void))block;

Use this to measure part of the block

Page 158: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)measureMetrics:(NSArray *)metrics automaticallyStartMeasuring:(BOOL)automaticallyStartMeasuring withBlock:(void (^)(void))block;

Use this to measure part of the block

Measures passed in metricsCurrently supports one metric: XCTPerformanceMetric_WallClockTime

Page 159: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)startMeasuring;- (void)stopMeasuring;

Isolate part of the block to measure

Page 160: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)startMeasuring;- (void)stopMeasuring;

Isolate part of the block to measure

May be called once per block invocation

Page 161: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)startMeasuring;- (void)stopMeasuring;

Isolate part of the block to measure

May be called once per block invocation

-startMeasuring requires automaticallyStartMeasuring:NO

Page 162: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyMore XCTestCase APIs

- (void)startMeasuring;- (void)stopMeasuring;

Isolate part of the block to measure

May be called once per block invocation

-startMeasuring requires automaticallyStartMeasuring:NO

-stopMeasuring called automatically after block

Page 163: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { [self measureBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); UseFileHandle(fileHandle); [fileHandle closeFile]; }]; }

Page 164: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { [self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:NO forBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); !

UseFileHandle(fileHandle); [fileHandle closeFile]; }]; }

Page 165: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { [self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:NO forBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); !

[self startMeasuring]; UseFileHandle(fileHandle); [self stopMeasuring]; [fileHandle closeFile]; }]; }

Page 166: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Measuring PreciselyExample

- (void)testUseFileHandlePerformance { [self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:NO forBlock:^{ NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:PATH]; XCTAssertNotNil(fileHandle); !

[self startMeasuring]; UseFileHandle(fileHandle); [self stopMeasuring]; [fileHandle closeFile]; }]; }

Page 167: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

DemoAdding performance tests

Page 168: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance TestingWrap-Up

Use new APIs to measure performance

Page 169: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance TestingWrap-Up

Use new APIs to measure performance

Set Baseline to detect regressions

Page 170: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance TestingWrap-Up

Use new APIs to measure performance

Set Baseline to detect regressions

Use Standard Deviation to show spread of measurements

Page 171: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Performance TestingWrap-Up

Use new APIs to measure performance

Set Baseline to detect regressions

Use Standard Deviation to show spread of measurements

Use Instruments to profile tests

Page 172: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing in Xcode 6

Page 173: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing in Xcode 6

Why test?

Page 174: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing in Xcode 6

Why test?

Adding tests

Page 175: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing in Xcode 6

Why test?

Adding tests

Asynchronous testing

Page 176: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Testing in Xcode 6

Why test?

Adding tests

Asynchronous testing

Performance testing

Page 177: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

More Information

Dave DeLong Developer Tools Evangelist [email protected]

Page 178: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Related Sessions

• Continuous Integration with Xcode 6 Marina Thursday 2:00PM

Page 179: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?

Labs

• Continuous Integration Lab Tools Lab C Thursday 2:00PM

Page 180: 414 Testing in Xcode DF - Apple Inc....Getting started Asynchronous testing Performance testing. Overview. Motivation Why test? Motivation Why test? Find bugs. Motivation Why test?