{"title":"Zucchini: iOS Testing Written in Ruby & CoffeeScript","html_url":"https://deallocatedobjects.com/posts/zucchini-visual-ios-testing-written-in-coffeescript","source_url":"http://www.zucchiniframework.org/","markdown_content":"[Zucchini](http://www.zucchiniframework.org/) is an awesome [cucumber](http://cukes.info/)-like visual testing framework for iOS. It works in a pretty awesome way by compiling [CoffeeScript](http://coffeescript.org/) down to [UIAutomation](http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html)-compliant Javascript, and then running the test with Instruments.app's command-line tool.\r\n\r\nAlso, As their site describes further, the whole system works very much like [Cucumber](http://cukes.info/), the popular ruby/rails testing gem:\r\n\r\n> A Zucchini feature file consists of sections bound to contexts of different application screens. Every screen you proceed to needs to be backed up by a CoffeeScript class describing all UI elements you want Zucchini to interact with as well as custom actions you feel like performing on that screen.\r\n\r\nHere's an example of one such class:\r\n\r\n``` coffeescript\r\n\r\nclass PostScreen extends Screen\r\n  anchor: -> view.navigationBars()[\"Post\"]\r\n  \r\n  constructor: ->\r\n    super 'post'\r\n    \r\n    extend @elements,\r\n    'Post': -> view.navigationBars()[\"Post\"].buttons()[\"Post\"]\r\n    \r\n    extend @actions,\r\n    'Type \"([^\"]*)\"$': (text) ->\r\n      messageArea = view.elements()['Message Text Area']\r\n      messageArea.setValue text\r\n\r\n```\r\n\r\nZucchini has an impressive set of features including:\r\n\r\n* Using a natural language for interaction scenarios, such as `Then on the \"Menu\" screen:`, etc.\r\n* The ability test/compare against screenshots.\r\n* Integration with Jenkins for full-on regression testing.\r\n\r\n> Zucchini only runs on Mac OS X 10.6 and 10.7 and requires XCode 4.2 as well as Ruby (at least 1.8.7).\r\n\r\n[The Zucchini site](http://www.zucchiniframework.org/) is full of really helpful links and installation instructions, so check it out, you can also find [the Zucchini project on Github here](https://github.com/playup/zucchini).","html_content":"<p><a href=\"https://web.archive.org/web/20120107231845/http://www.zucchiniframework.org/\">Zucchini</a> is an awesome <a href=\"https://web.archive.org/web/20120101212428/http://cukes.info/\">cucumber</a>-like visual testing framework for iOS. It works in a pretty awesome way by compiling <a href=\"http://coffeescript.org/\">CoffeeScript</a> down to <a href=\"https://web.archive.org/web/20120102170531/http://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/_index.html\">UIAutomation</a>-compliant Javascript, and then running the test with Instruments.app’s command-line tool.</p>\n\n<p>Also, As their site describes further, the whole system works very much like <a href=\"https://web.archive.org/web/20120101212428/http://cukes.info/\">Cucumber</a>, the popular ruby/rails testing gem:</p>\n\n<blockquote>\n<p>A Zucchini feature file consists of sections bound to contexts of different application screens. Every screen you proceed to needs to be backed up by a CoffeeScript class describing all UI elements you want Zucchini to interact with as well as custom actions you feel like performing on that screen.</p>\n</blockquote>\n\n<p>Here’s an example of one such class:</p>\n<figure class=\"code\" data-lang=\"coffeescript\"><figcaption><span class=\"lang\">CoffeeScript</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">class</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> PostScreen</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> extends</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> Screen</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">  anchor</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> -></span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> view.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">navigationBars</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()[</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Post\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">  constructor</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> -></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">    super</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> 'post'</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    extend</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> @elements,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">    '</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Post</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> -></span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> view.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">navigationBars</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()[</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Post\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">].</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">buttons</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()[</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"Post\"</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">    extend</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> @actions,</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">    '</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">Type \"([^\"]*)\"$</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">:</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (text) </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">-></span></span>\n<span class=\"line\"><span style=\"--shiki-light:#E36209;--shiki-dark:#FFAB70\">      messageArea</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> =</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> view.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">elements</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">()[</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">'Message Text Area'</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">      messageArea.</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">setValue</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> text</span></span></code></pre></figure>\n<p>Zucchini has an impressive set of features including:</p>\n\n<ul>\n<li>Using a natural language for interaction scenarios, such as <code>Then on the &quot;Menu&quot; screen:</code>, etc.</li>\n<li>The ability test/compare against screenshots.</li>\n<li>Integration with Jenkins for full-on regression testing.</li>\n</ul>\n\n<blockquote>\n<p>Zucchini only runs on Mac OS X 10.6 and 10.7 and requires XCode 4.2 as well as Ruby (at least 1.8.7).</p>\n</blockquote>\n\n<p><a href=\"https://web.archive.org/web/20120107231845/http://www.zucchiniframework.org/\">The Zucchini site</a> is full of really helpful links and installation instructions, so check it out, you can also find <a href=\"https://github.com/playup/zucchini\">the Zucchini project on Github here</a>.</p>","created_at":"2013-11-16T05:10:25.596Z","updated_at":"2013-11-16T05:10:25.596Z"}