mikeash.com pyblog/friday-qa-2011-07-22-writing-unit-tests.html commentshttp://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsmikeash.com Recent CommentsThu, 28 Mar 2024 22:04:59 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssjianhua - 2012-04-25 10:22:23http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentswhile(!finished &amp;&amp; [[NSProcessInfo processInfo] systemUptime] - start &lt;= 10) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; // do nothing <br /> <br />---&gt; It will block main thread execution, not work for some cases. <br /> <br /> <br />while(!block() &amp;&amp; [[NSProcessInfo processInfo] systemUptime] - start &lt;= 10) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate date]]; <br /> <br />---&gt; It is none blocking. <br /> <br /> <br />8e86b6c5f7ba58b0fb4e1c136157fe76Wed, 25 Apr 2012 10:22:23 GMTjianhua - 2012-04-25 09:12:29http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsHey Degutis; <br /> <br />How do you think using OCMock to solve dispatch_async delay execution issue? Could you help to explain more? Thank you. <br /> <br />&gt;&gt;&gt;&gt;&gt; In Ruby, mock dependencies are super easy to create (hence why the method "mock" is so useful in RSpec) and it's also possible, albeit slightly less convenient, in ObjC, using frameworks like OCMock.dcb412383b18d5d3797dcdb5568418dfWed, 25 Apr 2012 09:12:29 GMTJustin DeWind - 2011-08-02 17:25:03http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsThere are any number of options for unit testing in Objective-C. <br /> <br />I like, <br /> <br />[1] Kiwi: BDD framework similar to RSpec, <a href="http://www.kiwi-lib.info/">http://www.kiwi-lib.info/</a> <br />[2] Frank: Automated functional testing, <a href="http://github.com/moredip/Frank">http://github.com/moredip/Frank</a> <br />[3] OCHamcrest: Invaluable matcher library <br /> <br />I've also used Cedar but have transitioned to Kiwi.1189125455f8a2707758d4ef89418b88Tue, 02 Aug 2011 17:25:03 GMTStew Gleadow - 2011-07-30 05:23:54http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsI would also recommend Frank for automated functional testing. github.com/moredip/Frank <br /> <br />If you're from a Ruby background, Frank feels pretty natural because it uses Cucumber and Ruby to talk to your app over HTTP. Running cucumber from a CI build is pretty straightforward tooab74f58bfcb1ab120e339b112e12ef3bSat, 30 Jul 2011 05:23:54 GMTSteven Degutis - 2011-07-25 00:15:02http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsThere's an interesting RSpec-like framework for ObjC called OCDSpec at <a href="https://github.com/paytonrules/OCDSpec/">https://github.com/paytonrules/OCDSpec/</a> <br /> <br />Also, I found this statistic interesting: "FitNesse: Over 2200 unit tests run in 90 sec. Over 200 integration tests run in &lt; 1 min. Build/Test/Deploy &lt; 3 min." -- <a href="https://twitter.com/unclebobmartin/status/86521101974376448">https://twitter.com/unclebobmartin/status/86521101974376448</a> <br /> <br />A lot of this benefit comes from having mock-dependencies when the real dependency is either impossible, expensive, or impractical to use in testing. <br /> <br />In Ruby, mock dependencies are super easy to create (hence why the method "mock" is so useful in RSpec) and it's also possible, albeit slightly less convenient, in ObjC, using frameworks like OCMock.043b6e25ecee635ba6d4474cc0dd83f2Mon, 25 Jul 2011 00:15:02 GMTStan - 2011-07-24 10:54:00http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsNice article! Thumbs up! <br /> <br />Here it is one good example for integration testing - <a href="http://corner.squareup.com/2011/07/ios-integration-testing.html">http://corner.squareup.com/2011/07/ios-integration-testing.html</a> . The guys from squareup have released KIF - “Keep It Functional” framework.2793620ba3b57a956f50b0ebebe47e13Sun, 24 Jul 2011 10:54:00 GMTNikita Zhuk - 2011-07-23 16:40:08http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsEimantas: For functional testing through UI, there are (at least) couple of options: <br /> <br />- Apple's own UI Automation [1, 2]. You write your tests in JavaScript and execute them via Instruments. As far as I know, there isn't a straightforward way to actually automate running these tests on CLI. <br />- KiF [3] A "Keep it Functional" framework from Square. You write your functional tests in ObjC and run them from inside your application process. Can be easily automated and run from CLI. Can even record a video and/or take screenshots of your app while it's being tested or failing. Currently iOS-only, but OS X port is underway. <br /> <br /> <br />Any others? <br /> <br /> <br />[1] <a href="http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html">http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html</a> <br />[2] <a href="http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/">http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/</a> <br />[3] <a href="https://github.com/square/KIF#readme">https://github.com/square/KIF#readme</a>3688d83174efef383787d2448766669cSat, 23 Jul 2011 16:40:08 GMTEimantas - 2011-07-22 17:32:00http://www.mikeash.com/?page=pyblog/friday-qa-2011-07-22-writing-unit-tests.html#commentsRegarding the unit testing - coming from BDD/Ruby&amp;Rails background - the unit tests cover only the M part of the MVC design pattern. I actually miss testing of V &amp; C parts. What are possible functional testing facilities? Are there any solutions for automated UI testing (the V part)? And let's not forget the continuous integration! Any thoughts on the topics above? <br /> <br />Best regards1e70202c5ec8962913e6ffa56c230b65Fri, 22 Jul 2011 17:32:00 GMT