<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi<div><br></div><div>looks like #2 approach wins so I merged it.</div><div><br></div><div>Thanks!</div><div><br><div><div>On Jun 10, 2013, at 12:29 PM, Corinne Krych <<a href="mailto:corinnekrych@gmail.com">corinnekrych@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">+1 for #2. Indeed second approach2 is more objective-c in the syntax.<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 10 June 2013 10:15, Matthias Wessendorf <span dir="ltr"><<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I think I do prefer the approach #2 (the "mock helper" class)</div><div>
<br></div><div>-M</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">
On Fri, Jun 7, 2013 at 10:32 AM, Christos Vasilakis <span dir="ltr"><<a href="mailto:cvasilak@gmail.com" target="_blank">cvasilak@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
<div style="word-wrap:break-word">Hi team,<div><br></div><div>for further improvements of our unit tests we have switched the http mocking mechanism we use (our own NSURLProtocol impl) to the popular OHHTTPStubs[1] project, a library currently recommended by the AFNetworking networking lib we use.</div>
<div><br></div><div>The basic mechanism is straightforward to use and encapsulated in one method:</div><div><br></div><div><span style="line-height:16px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace">return [</span><span style="line-height:16px;color:rgb(51,51,51);font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace">OHHTTPStubsResponse</span><span style="line-height:16px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace"> </span><span style="line-height:16px;color:rgb(51,51,51);font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace">responseWithData</span><span style="line-height:16px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-weight:bold">:</span><span style="line-height:16px;color:rgb(51,51,51);font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace">data</span></div>
<div><pre style="line-height:16px;width:744px;font-size:12px;margin-bottom:0px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;word-wrap:break-word;padding:0px"><div> <span>statusCode:</span><span style="color:rgb(51,51,51)">status</span></div>
<div> <span>responseTime:</span><span style="color:rgb(51,51,51)">responseTime</span></div><div> <span>headers:</span><span style="color:rgb(51,51,51)">headers</span><span>];</span></div>
</pre><div><br></div></div><div>in which a stubbed response is returned to the client.</div><div><br></div><div>Now, based on this mechanism, we have abstracted a bit and created methods such as:</div><div><br></div><pre style="line-height:16px;font-size:12px;width:744px;margin-bottom:0px;font-family:Consolas,'Liberation Mono',Courier,monospace;margin-top:0px;word-wrap:break-word;padding:0px"><div><span style="font-weight:bold"> +</span> <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">void</span><span>)</span><span style="color:rgb(51,51,51)">mockResponse</span><span style="font-weight:bold">:</span><span>(</span><span style="color:rgb(51,51,51)">NSData</span><span style="font-weight:bold">*</span><span>)</span><span style="color:rgb(51,51,51)">data</span><span>;</span></div>
<div><span> <span style="font-weight:bold">+</span> <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">void</span><span>)</span><span style="color:rgb(51,51,51)">mockResponseStatus</span><span style="font-weight:bold">:</span><span>(</span><span style="color:rgb(68,85,136);font-weight:bold">int</span><span>)</span><span style="color:rgb(51,51,51)">status</span><span>;</span></span></div>
<div> <span style="font-weight:bold">+</span> <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">void</span><span>)</span><span style="color:rgb(51,51,51)">mockResponseTimeout</span><span style="font-weight:bold">:</span><span>(</span><span style="color:rgb(51,51,51)">NSData</span><span style="font-weight:bold">*</span><span>)</span><span style="color:rgb(51,51,51)">data</span> <span style="color:rgb(51,51,51)">status</span><span style="font-weight:bold">:</span><span>(</span><span style="color:rgb(68,85,136);font-weight:bold">int</span><span>)</span><span style="color:rgb(51,51,51)">status</span> <span style="color:rgb(51,51,51)">responseTime</span><span style="font-weight:bold">:</span><span>(</span><span style="color:rgb(51,51,51)">NSTimeInterval</span><span>)</span><span style="color:rgb(51,51,51)">responseTime</span><span>;</span></div>
<div><br></div></pre><div>This gives the advantages that a) clearly indicate what http scenario we are testing and b) remove params that don't make sense for the particular scenario under testing e.g. that is we simulate a status of (404) but we need to pass all params eg. data, interval, timeout, etc. But this doesn't limit us, we can do that if we want and use the full blown method with all the params attached.</div>
<div><br></div><div>I have created two branches in my fork, one that uses a blocks approach inside the testing class [2] and one that the functionality is extracted in a helper class that the testing classes can use [3]. The second approach was created because there was common code and didn't want to duplicate it over the testing classes. </div>
<div><br></div><div>I would be interesting to know what is your comments on it?</div><div><br></div><div>Thanks,</div><div>Christos</div><div><br></div><div><br></div><div>[1] <a href="https://github.com/AliSoftware/OHHTTPStubs" target="_blank">https://github.com/AliSoftware/OHHTTPStubs</a></div>
<div>[2] <a href="https://github.com/cvasilak/aerogear-ios/blob/ohhttpstubs/AeroGear-iOS/AeroGear-iOSTests/AGRestAdapterTests.m#L33-L51" target="_blank">https://github.com/cvasilak/aerogear-ios/blob/ohhttpstubs/AeroGear-iOS/AeroGear-iOSTests/AGRestAdapterTests.m#L33-L51</a></div>
<div>[3] <a href="https://github.com/cvasilak/aerogear-ios/blob/ohhttpstubs.helper/AeroGear-iOS/AeroGear-iOSTests/utils/AGHTTPMockHelper.m" target="_blank">https://github.com/cvasilak/aerogear-ios/blob/ohhttpstubs.helper/AeroGear-iOS/AeroGear-iOSTests/utils/AGHTTPMockHelper.m</a></div>
<div>[4] </div><div> </div><div><br></div></div><br></div></div>_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org" target="_blank">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br>
<br clear="all"><div><br></div>-- <br>Matthias Wessendorf <br>
<br>blog: <a href="http://matthiaswessendorf.wordpress.com/" target="_blank">http://matthiaswessendorf.wordpress.com/</a><br>sessions: <a href="http://www.slideshare.net/mwessendorf" target="_blank">http://www.slideshare.net/mwessendorf</a><br>
twitter: <a href="http://twitter.com/mwessendorf" target="_blank">http://twitter.com/mwessendorf</a>
</font></span></div>
<br>_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br></blockquote></div><br></div>
_______________________________________________<br>aerogear-dev mailing list<br><a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/aerogear-dev</blockquote></div><br></div></body></html>