Download - Unit Testing in iOS - Ninjava Talk
![Page 1: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/1.jpg)
Presented by: Ross SharrottLong Weekend KK
Follow me/us: @rsharrott @long_weekend
![Page 2: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/2.jpg)
• IT & Sales Managers•Entrepreneurs•Geeks•Tokyo, Melbourne, New York
![Page 3: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/3.jpg)
![Page 4: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/4.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/5.jpg)
• Practical > Theoretical
• The world is not perfect.
• We are lazy.
![Page 6: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/8.jpg)
![Page 9: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/9.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/10.jpg)
![Page 11: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/11.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/13.jpg)
< 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/14.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/15.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/16.jpg)
![Page 17: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/18.jpg)
Unit Testing:– GHUnit– OCUnit–Continuous Integration
UI & Integration:– Automator, FoneMonkey– iCuke, UISpec, etc.
![Page 19: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/19.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/20.jpg)
![Page 21: Unit Testing in iOS - Ninjava Talk](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/21.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/22.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/23.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/24.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/25.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/26.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022052522/54627e28af7959e2278b6518/html5/thumbnails/27.jpg)
Follow me/us:@rsharrott @long_weekend