+ All Categories
Home > Technology > Unit Testing in iOS - Ninjava Talk

Unit Testing in iOS - Ninjava Talk

Date post: 12-Nov-2014
Category:
Upload: long-weekend-llc
View: 2,091 times
Download: 2 times
Share this document with a friend
Description:
Talk I gave about unit testing for iPhone to the Ninjava group in Tokyo.
Popular Tags:
27
Presented by: Ross Sharrott Long Weekend KK Follow me/us: @rsharrott @long_weekend
Transcript
Page 1: Unit Testing in iOS - Ninjava Talk

Presented by: Ross SharrottLong Weekend KK

Follow me/us: @rsharrott @long_weekend

Page 2: Unit Testing in iOS - Ninjava Talk

• IT & Sales Managers•Entrepreneurs•Geeks•Tokyo, Melbourne, New York

Page 3: Unit Testing in iOS - Ninjava Talk
Page 4: Unit Testing in iOS - Ninjava Talk

• B2C Apps• Contract Development– Specialize in iOS & Android

• Consulting– Training–Mobile Strategy for Enterprise– App Development strategy &

implementation

Page 5: Unit Testing in iOS - Ninjava Talk

• Practical > Theoretical

• The world is not perfect.

• We are lazy.

Page 6: Unit Testing in iOS - Ninjava Talk

1. Why Unit Test?2. Why don’t iOS Devs Do

It?3. The Tools4. Q&A

Page 7: Unit Testing in iOS - Ninjava Talk

1. Why Unit Test?2. Why don’t iOS Devs Do

It?3. The Tools4. Q&A

Page 8: Unit Testing in iOS - Ninjava Talk
Page 9: Unit Testing in iOS - Ninjava Talk

• It takes longer to write tests.• I’m the only developer (and I’m

amazing)• That’s QA’s job (I’m a developer)• My code takes input from someone

else.• My boss doesn’t give me enough

time to test.

Page 10: Unit Testing in iOS - Ninjava Talk
Page 11: Unit Testing in iOS - Ninjava Talk

• Tests save time.• Your own code looks like new code

after 6 months.• QA is there to help you find real /

obscure problems, not regressions.• Unit testing is for what you do with

inputs.• Your boss will give you some time to

get started, just ask.

Page 12: Unit Testing in iOS - Ninjava Talk

1. Why Unit Test?2. Why don’t iOS Devs Do

It?3. The Tools4. The future?

Page 13: Unit Testing in iOS - Ninjava Talk

< SDK 2.2 had no unit testing at all. Then Unit testing in Xcode, frankly, sucked.– Sentest reported the unit tests at build

time.– Application State was inaccessible.– Logic tests only.– Hard to debug tests.– IDE integration was poor – non-existent.

Page 14: Unit Testing in iOS - Ninjava Talk

• Functional & Application testing basically did not exist.

• Continuous Integration was nigh impossible.

• We are all spoiled by the tools in most other worlds – selenium, _test, _cover, _mock

Page 15: Unit Testing in iOS - Ninjava Talk

• GHUnit–Made testing on the device & with state

possible

• FoneMonkey–Made selenium like testing possible

• Various Others…• The problem:– No IDE integration, somewhat annoying

to run.

Page 16: Unit Testing in iOS - Ninjava Talk
Page 17: Unit Testing in iOS - Ninjava Talk

1. Why Unit Test?2. Why don’t iOS Devs Do

It?3. The Tools4. Q&A

Page 18: Unit Testing in iOS - Ninjava Talk

Unit Testing:– GHUnit– OCUnit–Continuous Integration

UI & Integration:– Automator, FoneMonkey– iCuke, UISpec, etc.

Page 19: Unit Testing in iOS - Ninjava Talk

• Pros– Running a subset of tests.– Nice viewer to see the test results.– Setup/Teardown on class or methods– Can run on Continuous Integration– Can read Sentest so you can switch later

• Con– Additional setup, required for every project– New versions of Xcode can break this setup

Page 20: Unit Testing in iOS - Ninjava Talk
Page 21: Unit Testing in iOS - Ninjava Talk

• Pros– Easy to run with Xcode (CMD + U)– Easy to create new tests (CMD + N)– (Almost) no setup– Can be run on Continuous Integration

• Cons– No class setup/teardown–Must run the entire suite every time

Page 22: Unit Testing in iOS - Ninjava Talk

• New test: CMD+N• Objective-C Test Case• You get something like this:- (void)testAppDelegate{ id yourApplicationDelegate = [[UIApplication

sharedApplication] delegate]; STAssertNotNil(yourApplicationDelegate,

@"UIApplication failed to find the AppDelegate");}

Page 23: Unit Testing in iOS - Ninjava Talk

Deinflector *bulldog = [[Deinflector alloc] init];

NSArray *results; NSString* msg = @"expected deinflected string did not match!”;

// Check deinflection types results = [bulldog go:@" かけた "]; STAssertEqualStrings([[results objectAtIndex:0] word], @" かけた ", @"1st %@"); STAssertEqualStrings([[results objectAtIndex:1] word], @" かける ", @"2nd %@", msg); STAssertEqualStrings([[results objectAtIndex:2] word], @" かく ", @"3rd %@", msg);

Page 24: Unit Testing in iOS - Ninjava Talk

• CMD + U• Xcode will build & run the test suite• You get in console:Test Case '-[CardTagTest

testUpdateLevelCounts]' passed (0.345 seconds).

Test Suite 'CardTagTest' finished at 2011-10-20 05:44:39 +0000.

Executed 3 tests, with 0 failures (0 unexpected) in 1.528 (1.529) seconds

Page 25: Unit Testing in iOS - Ninjava Talk

• Good News:– It can be done using xcodebuild & the

simulator–Most of the popular CI’s can work

• Bad News:–Must have xcode installed – so need a mac– OCUnit doesn’t put out junit output by default

• Tools exist for this

– Not a lot of Code Coverage tools available yet

Page 26: Unit Testing in iOS - Ninjava Talk

• Automator– Test automator, uses javascript– Included in Instruments

• iCuke– New to the scene, seems like a good

start but we haven’t jumped in yet.Future (testing) proof your projects:

Set accessibility tags in your apps

Page 27: Unit Testing in iOS - Ninjava Talk

Follow me/us:@rsharrott @long_weekend


Recommended