<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Making the Complex Simple &#187; Frameworks</title>
	<atom:link href="http://simpleprogrammer.com/category/frameworks/feed/" rel="self" type="application/rss+xml" />
	<link>http://simpleprogrammer.com</link>
	<description>Software Development from John Sonmez&#039;s Perspective</description>
	<lastBuildDate>Tue, 07 Feb 2012 17:47:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='simpleprogrammer.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Making the Complex Simple &#187; Frameworks</title>
		<link>http://simpleprogrammer.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://simpleprogrammer.com/osd.xml" title="Making the Complex Simple" />
	<atom:link rel='hub' href='http://simpleprogrammer.com/?pushpress=hub'/>
		<item>
		<title>OAuth and REST in Android: Part 2</title>
		<link>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/</link>
		<comments>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 20:49:34 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/06/04/oauth-and-rest-in-android-part-2/</guid>
		<description><![CDATA[In my last post we went over OAuth in general and we looked at how to use a Java library called Leeloo to authenticate with a service providing an OAuth 2 implementation. Now that we are able to authenticate a service with OAuth, we need to be able to actually use that service to do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1346&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/">last post</a> we went over OAuth in general and we looked at how to use a Java library called Leeloo to authenticate with a service providing an OAuth 2 implementation.</p>
<p>Now that we are able to authenticate a service with OAuth, we need to be able to actually use that service to do something useful.</p>
<p>Many popular web service APIs like Facebook and Twitter provide a REST based implementation.</p>
<p>In this post I’ll show you how to easily connect to one of these web services from Android and parse any responses you get back.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/06/androidrest.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="AndroidREst" border="0" alt="AndroidREst" src="http://complextosimple.files.wordpress.com/2011/06/androidrest_thumb.png?w=422&#038;h=366" width="422" height="366" /></a></p>
<h2></h2>
<h2>Should I use a REST library?</h2>
<p>This is a valid question we should address before getting into the details.</p>
<p>My answer to this question is basically “no.”</p>
<p>I first tried the approach of using a REST library to make it easier to communicate to a REST based web service, but quickly found the overhead of the library was more than the benefit it provided.</p>
<p>If you come from a background of calling XML and SOAP based web services, you might be surprised by this answer.&#160; With SOAP based web services it was a huge benefit to use a library to generate a proxy for you to call the web service and let you not have to worry about parsing XML and SOAP headers.</p>
<p>With REST it is completely different.&#160; The whole point of moving to REST based web services is to simplify the process of calling web services.</p>
<p>Most REST based web service interfaces are extremely simple to use.&#160; The idea is that the URL itself contains as much of the data as possible and additional data is included in the POST body.</p>
<p>By adding the complexity of learning a REST library and implementing the proper interfaces required to make it work seamlessly, we can easily add more complexity and overhead than just creating a HTTP request ourselves and parsing the responses.</p>
<p>For this approach I am going to show you how to do just that.</p>
<h2></h2>
<h2>Calling the REST service</h2>
<p>In order to call a REST service in Android we are going to first have to discover and understand the REST API provided to us, then make the appropriate calls with the OAuth token we got from authenticating.&#160; Finally, we will parse the result of the call and get back our response.</p>
<p><strong>Discovering the API</strong></p>
<p>Because REST is not really a standard, but rather an ideal, there is not a standard way REST APIs are implemented.</p>
<p>You’ll have to take a look at the documentation for the REST API you want to call to figure out exactly what a call should look like.</p>
<p>In general though a REST API will involve making some kind of HTTP GET, POST, PUT or DELETE request and passing data through the URL or in the request body.</p>
<p>Here is an example of the Dailymile.com API which I have been recently integrating my app to use.</p>
<p>You can see the full <a href="http://www.dailymile.com/api/documentation">API documentation here.</a></p>
<p>For this API, I am going to show you how I am creating a workout entry using a post.</p>
<p><strong>Making the REST call</strong></p>
<p>In order to make a REST call in Android, we are going to use a <em>HttpClient</em> object and the appropriate http request class.</p>
<p>In this example we are going to use the JSONObject class to create some data in JSON format that we can pass to the REST call by embedding it in the post.</p>
<p>I looked at the API for posting a workout entry to Dailymile, and the format of the request should look like this:</p>
<p><a title="https://api.dailymile.com/entries.json?oauth_token=" href="https://api.dailymile.com/entries.json?oauth_token">https://api.dailymile.com/entries.json?oauth_token=</a>&lt;token&gt;</p>
<p>The API also indicates that it expects the post body to contain some JSON and gives us a list of required and optional entries that need to be in that JSON object.</p>
<p>Let’s take a look at how I am making this call and then we’ll break it down some.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:f8610da6-d295-47dd-9ae4-a02b7d443e4f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: java; pad-line-numbers: true;">
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(
	&quot;https://api.dailymile.com/entries.json?oauth_token=&quot; 
    + token);

httpPost.setHeader(&quot;content-type&quot;, &quot;application/json&quot;);
JSONObject data = new JSONObject();

data.put(&quot;message&quot;, dailyMilePost.getMessage());
JSONObject workoutData = new JSONObject();
data.put(&quot;workout&quot;, workoutData);
workoutData.put(&quot;activity_type&quot;, dailyMilePost.getActivityType());
workoutData.put(&quot;completed_at&quot;, dailyMilePost.getCompletedAt());
JSONObject distanceData = new JSONObject();
workoutData.put(&quot;distance&quot;, distanceData);
distanceData.put(&quot;value&quot;, dailyMilePost.getDistanceValue());
distanceData.put(&quot;units&quot;, dailyMilePost.getDistanceUnits());
workoutData.put(&quot;duration&quot;, dailyMilePost.getDurationInSeconds());
workoutData.put(&quot;title&quot;, dailyMilePost.getTitle());
workoutData.put(&quot;felt&quot;, dailyMilePost.getFelt());

StringEntity entity = new StringEntity(data.toString());
httpPost.setEntity(entity);

HttpResponse response = httpClient.execute(httpPost);
</pre>
</pre>
</div>
<p>&#160;</p>
<p>You can see that I am first creating an <em>HttpClient</em> object and an <em>HttpPost</em> object.&#160; The <em>HttpPost </em>has its URL set to the URL for the API call and I am adding a query string parameter to provide the OAuth token we got when when authenticated in my <a href="http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/">previous post</a>.</p>
<p>I set the content type to be JSON so that we can get back a JSON object from the API call and so it knows that we are passing JSON data.</p>
<p>Then I construct a JSON object in the format specified by the API.&#160; The way to construct the JSON object is to basically create a set of keys and values that are specified by the API you are calling.&#160; In this instance I have a “message” key which I put the message data into.&#160; </p>
<p>The only tricky part is that JSON objects can be nested.&#160; So if you look at the key “workout” in the example above, I am creating a brand new JSON object to use as the value for that key which has its own subkeys which could contain more JSON objects.</p>
<p>Doing it this way is much more simple than trying to construct the string yourself.&#160; The string we end up constructing will look something like this:</p>
<blockquote>
<pre>{&quot;message&quot;:&quot;fun!&quot;,&quot;workout&quot;:{&quot;distance&quot;:{&quot;value&quot;:5,&quot;units&quot;:&quot;miles&quot;},</pre>
<pre>&quot;activity_type&quot;:&quot;running&quot;}}</pre>
</blockquote>
<pre><font face="Verdana"></font>&#160;</pre>
<div>
<pre><font face="Verdana">Finally, I put the JSON data into a <em>StringEntity</em> class and set it as the entity on the HTTP Post.  Then we can call execute on the <em>HttpClient</em> to execute the HTTP POST.</font></pre>
</div>
<div>
<pre><font face="Verdana"></font>&#160;</pre>
</div>
<div>
<pre><font face="Verdana"><strong>Handling the response</strong></font></pre>
<pre><strong><font face="Verdana"></font></strong></pre>
</div>
<div>
<pre><strong><font face="Verdana"></font></strong></pre>
</div>
<div>Now that we have actually made the call to the REST service method we can handle the response by creating another JSONObject from the HttpResponse that is returned.</div>
<div>&#160;</div>
<div>Let’s look at that code and then we can go over what is happening.</div>
<div>&#160;</div>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:6c90c3b6-702d-4830-b348-12d2efb89b0a" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: java;">
HttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
JSONObject responseJSON = new JSONObject(responseString);
int workoutId = responseJSON.getInt(&quot;id&quot;);
</pre>
</pre>
</div>
<p>All we are doing in this case is getting the response from the execute call on the <em>HttpClient</em> object, then using <em>EntityUtils.toString</em> to convert the response’s entity to a string representation.&#160; Finally, we construct a new <em>JSONObject</em> from that string.</p>
<p>We can then easily extract any data out of the JSON object by using the methods on that JSON object that let us get typed values out of it.&#160; For this example, I know that I am getting back some JSON that has a key “id” which is the id of the workout I created with my POST.</p>
<h2>It is really that simple</h2>
<p>The example I am showing you here is one of the more complex examples of calling a REST based API, because we are having to POST and parse JSON data.</p>
<p>In many API calls, you can just use an HTTP GET or a POST without any data to accomplish what you need to in the API.</p>
<p>Some REST based APIs will allow or require data to be passed in a different format, but most of them use JSON notation, which I find the easiest to work with.</p>
<p>Hopefully with these series of posts you can now authenticate against an OAuth 2 based service and make calls to the API to get and manipulate data in Android.</p>
<p>If you have any questions, feel free to drop me a line or post in the comments below.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1346&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/06/androidrest_thumb.png" medium="image">
			<media:title type="html">AndroidREst</media:title>
		</media:content>
	</item>
		<item>
		<title>OAuth and REST in Android: Part 1</title>
		<link>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/</link>
		<comments>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/#comments</comments>
		<pubDate>Wed, 25 May 2011 18:02:47 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1338</guid>
		<description><![CDATA[I recently had the fun experience of learning a bit about both OAuth and making REST web service calls in Android and since I didn’t find much good material out there, I thought I would share it here. Let&#8217;s talk about OAuth The first thing you NEED to know about OAuth is that OAuth and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1338&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had the fun experience of learning a bit about both OAuth and making REST web service calls in Android and since I didn’t find much good material out there, I thought I would share it here.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/05/oauthpicture.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="OAuthPicture" src="http://complextosimple.files.wordpress.com/2011/05/oauthpicture_thumb.png?w=467&#038;h=259" alt="OAuthPicture" width="467" height="259" border="0" /></a></p>
<h2>Let&#8217;s talk about OAuth</h2>
<p>The first thing you NEED to know about OAuth is that OAuth and OAuth 2.0 are not the same protocol.</p>
<p>From the <a href="http://hueniverse.com/2010/05/introducing-oauth-2-0/">OAuth guide</a> on hueniverse:</p>
<blockquote><p><strong>OAuth 2.0 is a completely new protocol</strong> and is not backwards compatible with previous versions. However, it retains the overall architecture and approach established by the previous versions, and the same introduction (from the Official Guide to OAuth 1.0) still very much applies.</p></blockquote>
<p>But, before we get into that, let’s talk a little bit about what OAuth is for.</p>
<p>OAuth basically does two things for a web site providing some kind of service or API that another application might want to use.</p>
<ol>
<li>It prevents the consuming application from needing to store or have the user’s login and password.</li>
<li>It allows for a scoping of access to the producer’s services.  (For example, a user might be able to login to a site and access all of the features, but an app using OAuth might only be granted permissions to do certain things.)</li>
</ol>
<p>So now that we know why, let’s talk about how both OAuth and OAuth 2 work from a high level perspective.</p>
<p>From the app developer perspective, the flow goes something like this:</p>
<ol>
<li>You register your application with the service you want to access and get some unique identifiers for your application.</li>
<li>When you want to access something on the service, you make a request to the service using your unique identifier and telling it where to send the user after they authenticate.  (Usually you would launch a browser window here.)</li>
<li>User will login to the service using the browser window you launched for that service and choose to grant your application certain privileges.</li>
<li>The service will redirect the user to the callback url you provided and include a code you can use to get an access token.</li>
<li>You call the service one more time passing in your unique identifier and the code you got back and the service grants you an access token which you can use to access services you have been granted permissions for.</li>
<li>The next time you need to make a call you can just use that access token instead of going through this whole process again.  (At least till it expires.)</li>
</ol>
<p>It really isn’t that complicated; the basic idea is that you tell the service who you are and ask the user the authenticate themselves and grant permissions to your application.  Then you prove that you got the response from the server and that it is still you and the service gives you a special pass to access the service.</p>
<p>The real difference between OAuth and OAuth 2 is the protocol itself, not the process.  So this is both good and bad.</p>
<p>Good, because we don’t have to change our process flow and understand something different.</p>
<p>Bad, because we can’t use the same libraries to access an OAuth 2 implementation as we do for an OAuth implementation and vice versa.  There is no backwards compatibility.</p>
<p>For the purpose of this post I am going to show how to use the <a href="https://bitbucket.org/smartproject/oauth-2.0/wiki/Home">Leeloo library</a> to connect to an OAuth 2 service.</p>
<h2></h2>
<h2></h2>
<h2></h2>
<h2>Connecting to OAuth 2.0</h2>
<p><strong>Download the library</strong></p>
<p>The first thing you will want to do is to get the latest version of the Leeloo library.  It has moved to the Apache Amber project, so this link might change, but for now I found the <a href="https://bitbucket.org/smartproject/oauth-2.0/wiki/Home">ready to download binaries here</a>.</p>
<p><strong>Configure build path</strong></p>
<p>Once you have the library downloaded you’ll want to add the following jars to your build path:</p>
<ul>
<li>jettison-1.2.jar</li>
<li>oauth2-client.jar</li>
<li>oauth2-common-0.1.jar</li>
<li>slf4j-api.1.6.1.jar</li>
</ul>
<p><strong>Make initial request for authorization</strong></p>
<p>Make sure you already have a unique client id created with the service you are going to access.  Most services out there like Twitter have a page where you can request one for your application.</p>
<p>Once you have this, you will use this to create a url that you will redirect the user of your application to.</p>
<p>In the code snippet below, I am creating the url and then creating a new Intent in Android that will open a web browser at that url.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:b54fdd53-471a-4d5b-bcfe-90cede501c10" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java; pad-line-numbers: true;">
OAuthClientRequest request = null;
request = OAuthClientRequest
       .authorizationLocation(authenticationUrl)
	   .setClientId(&quot;&lt;your client id&gt;&quot;).setRedirectURI(&quot;&lt;your redirect url&gt;&quot;)
		.buildQueryMessage();

Intent intent = new Intent(Intent.ACTION_VIEW,
        Uri.parse(request.getLocationUri() + &quot;&amp;response_type=code&quot;));
startActivity(intent);
</pre></p>
</div>
<p>A couple of things to note about this code snippet:</p>
<ul>
<li>You’ll need to replace client id with your client id and redirect URI with your redirect URI.</li>
<li>The redirect URI for an Android application is going to be some protocol that doesn’t really exist, but you can tell your application to respond to.  (We’ll cover that in the next step, but you might have some URI like myapp://oauthresponse)</li>
<li>I had to add a “&amp;response_type=code” to the end of my URL because the authentication service required it.  You might have to look and see how the service you are trying to access expects requests to be formed.</li>
</ul>
<p><strong>Configure your application to respond to your unique URI</strong></p>
<p>In the previous step we had set the redirect to a unique URI like “myapp://oauthresponse”, now you will need to configure the activity you want to handle the response from the service to intercept that protocol.</p>
<p>You can do this by adding an intent filter to that activity like so:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:159a20e7-915a-4838-ae21-d2f51631ac80" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: xml;">
&lt;intent-filter&gt;
	&lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;
	&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
	&lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;
	&lt;data android:scheme=&quot;myapp&quot; android:host=&quot;oauthresponse&quot;/&gt;
&lt;/intent-filter&gt;
</pre></p>
</div>
<p>With this intent filter we are telling our activity to respond to a URI request in the form of “myapp://oauthresponse”.</p>
<p><strong>Configure your activity to respond to handle the intent you registered to receive</strong></p>
<p>Next we’ll want to set up an override in our activity to handle the new intent that will be called on our activity.  We can then pull the code the service gave us out and use that to request a real token.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:8d931558-fd6f-4c02-ab34-70662ddb23dc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
@Override
protected void onNewIntent(Intent intent)
{
	Uri uri = intent.getData();

   if (uri != null &amp;&amp; uri.toString()
           .startsWith(&quot;myapp://oauthresponse&quot;))
	{
        String code = uri.getQueryParameter(&quot;code&quot;);
        // ...
   }
}
</pre></p>
</div>
<p>This code will allow us to respond to the intent that will be fired by the web browser when the service redirects the user to “myapp://oauthresponse.”</p>
<p><strong>Exchange the code for a token</strong></p>
<p>Next we need to get a real token instead of a code.  When the user typed in their username and password and granted access to our application, the server called our callback URI with a code that we extracted in the last step.</p>
<p>Now we can pass that code back up to the server along with our client secret and client id and get an access token.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:80bbab4b-6883-4451-a09a-7b577db81b4f" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
OAuthClientRequest request = null;

request = OAuthClientRequest.tokenLocation(&quot;&lt;service request URL&gt;&quot;)
	.setGrantType(GrantType.AUTHORIZATION_CODE)
   .setClientId(&quot;&lt;your client id&gt;&quot;)
	.setClientSecret(&quot;&lt;your client secret&gt;&quot;)
	.setRedirectURI(&quot;myapp://oauthresponse&quot;)
	.setCode(code)
	.buildBodyMessage();

OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
String token = response.getAccessToken();

</pre></p>
</div>
<p>In this bit of code we are sending back to the server all the information we have that identifies our application as well as the code that proves the user allowed us to access that service.</p>
<p>Then we get back an access token from the server.  I would recommend you save this access token so that you don’t have to do this reauthentication in the future.</p>
<h2>Wrapping it up</h2>
<p>So what we have been able to do here is to redirect a user to the right page to authenticate our application, and then wire up our activity to respond to the redirect the service gives us in order to ultimately get an access token we can use to prove we are authorized to access that service on behalf of the user.</p>
<p>Be cautious though, because not everyone is implementing OAuth 2.0 exactly the same way, since the spec is not finalized.  So you might run into issues where things aren’t working exactly as laid out in this post.  If that is the case, you may have to modify a URL that is generated or something along those lines.</p>
<p>In my next post, I’ll show you what you can actually do with your authorization token.  We’ll go through calling a REST based API web service from Android.</p>
<p>Feel free to post any questions in comments.  I used this code to connect to the Dailymile.com API in my <a href="https://market.android.com/details?id=com.pacemaker.android">PaceMaker application</a>.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1338/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1338&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/05/oauthpicture_thumb.png" medium="image">
			<media:title type="html">OAuthPicture</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting up to BAT: Building a True DSL</title>
		<link>http://simpleprogrammer.com/2011/05/14/getting-up-to-bat-building-a-true-dsl/</link>
		<comments>http://simpleprogrammer.com/2011/05/14/getting-up-to-bat-building-a-true-dsl/#comments</comments>
		<pubDate>Sun, 15 May 2011 03:24:52 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[BAT]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/05/14/getting-up-to-bat-building-a-true-dsl/</guid>
		<description><![CDATA[If you’ve made it this far with your BAT implementation, you have finally arrived. Not to say that you’ll ever be done expanding your automation framework and building and improving your BATs, but you are at the point of having a mature usable BAT framework and you can be proud of that accomplishment. If you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1329&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you’ve made it this far with your BAT implementation, you have finally arrived.</p>
<p>Not to say that you’ll ever be done expanding your automation framework and building and improving your BATs, but you are at the point of having a mature usable BAT framework and you can be proud of that accomplishment.</p>
<p>If you truly want to see where the rabbit hole goes though… Read on</p>
<h2>Taking it to 11</h2>
<p><a href="http://complextosimple.files.wordpress.com/2011/05/spinal_tap_but_it_goes_to_eleven.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="spinal_tap_but_it_goes_to_eleven" border="0" alt="spinal_tap_but_it_goes_to_eleven" src="http://complextosimple.files.wordpress.com/2011/05/spinal_tap_but_it_goes_to_eleven_thumb.jpg?w=485&#038;h=273" width="485" height="273" /></a></p>
<p>If you have designed a good automation framework for writing your BATs, you will most likely have created an internal domain specific language (DSL).</p>
<p>What is an internal DSL?</p>
<p>Basically it is a set of APIs and rules built in another language that function as their own language.</p>
<p>You might have some code that looks like this:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:08f381ea-bda8-4f72-ab40-6ac923941fc7" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp; pad-line-numbers: true;">
Pages.Login.Goto();
Pages.Login.LoginWithDefaultUser();
Pages.Customers.Goto();
Pages.Customers.AddNewCustomer();
</pre>
</pre>
</div>
<p>&#160;</p>
<p>You can see how this code is really looking like a language itself.&#160; It is hard to tell if this code is even C# or Java.</p>
<p>This is a good example of an internal DSL.</p>
<p>If we were to take this same section of a BAT test and write it as an external DSL, it might look something like this:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:521b3b0f-ee9e-4256-8083-4b36a0085593" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: plain;">
LOGIN WITH DEFAULT-USER
ADD-CUSTOMER WITH DEFAULT-CUSTOMER

</pre>
</pre>
</div>
<p>&#160;</p>
<p>With a true DSL we can simplify even further to get right down to the bare minimum set of commands we need to execute what we want in our application.</p>
<h2>How to implement a DSL?</h2>
<p>There are a number of tools and techniques that can be used to create a DSL.&#160; I’ll hit on some of those a bit later on, but first we need to design the DSL itself.</p>
<p>Designing a DSL can be challenging, but I have found the best approach is to use a similar approach to what we used to <a href="http://simpleprogrammer.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/">design our automation framework</a>.</p>
<p>It is best to work backwards from the syntax that would make your BAT the easiest to write and the most clear.&#160; Once you have done that you can worry later about implementing the DSL to support the syntax you have come up with.</p>
<p>You should focus on creating a limited vocabulary for your DSL so that it will be easy for someone to learn and know what their options are.</p>
<p>The more restrictions we put into a DSL the easier that DSL becomes for doing a specific purpose.</p>
<p><strong>We want to give the user of a DSL no more options than required for what they want to do and no less.</strong></p>
<p>This isn’t always easy to do.&#160; It often requires some careful thought and refinement.</p>
<p>Your DSL should also use terminology and phrases that are familiar to the business domain of your application.&#160; By doing this you will make it so someone understanding your application will understand BATs written in that DSL.</p>
<p>I also always try to make a BAT DSL read as much as plain English as possible.</p>
<p>Once you have designed the DSL, you will need a way to implement it.&#160; </p>
<p>I’ve written about <a href="http://simpleprogrammer.com/2010/03/10/internal-dsl-becomes-external-dsl/">using ANTLR to create an external DSL</a>.&#160; Also I have written a review on a <a href="http://simpleprogrammer.com/2010/04/16/book-review-the-definitive-antlr-reference-building-domain-specific-languages/">book that I recommend for learning ANTLR</a>.</p>
<p>Microsoft also has a <a href="http://archive.msdn.microsoft.com/vsvmsdk">DSL SDK you can use in VS2010</a>, although I haven’t used it myself.</p>
<p>The basic idea behind implementing a DSL is that you have to take some sort of grammar you design for your DSL, parse it into a syntax tree, then use that tree to generate code that will actually perform the actions.</p>
<p>It is by no means a trivial task, but using a tool like ANTLR, makes it much simpler than trying to completely generate a parser and execution engine yourself.</p>
<h2>Why even bother?</h2>
<p>Creating a DSL for your BATs is completely optional, but there are some significant benefits to doing so.</p>
<p>The biggest one I have found is that you are much more likely to get business people to write BATs if you have a simple DSL they can use to create them.&#160; Once you get everyone using BATs to define behavior and requirements, communication becomes much more simple.</p>
<p>Another great thing about creating a DSL is that you can create a runner that can interpret the DSL BAT scripts which can be run on any machine.&#160; Typically, to run BATs created in Java or C#, you would need a C# or Java compiler and a test runner, etc.&#160; By creating a DSL and a stand alone executor, you can very easily allow anyone to run BATs with little to no setup.</p>
<p>Writing your BATs in a DSL will also make writing the BATs and understanding them much easier.&#160; A good DSL can get rid of all the little language and API nuances that don’t really add information to the specific domain you are working in.&#160; A good DSL strips information down to the minimum amount needed and is able to do so, because it assumes the context is your application’s business domain.</p>
<p>You will also find that you are better able to separate framework from tests when you have a DSL in place.&#160; One issue that many teams face when creating a BAT framework is that some people come along and write lower level code in the higher level BATs.&#160; This creates a problem because it is hard to force someone to use the higher level API when the framework and the BAT code are the same language.</p>
<h2>Wrapping it up</h2>
<p>So that completes my series on Getting up to BAT.</p>
<p>Hopefully you have learned enough to be able to implement your own BAT framework and get BATs running for your application.</p>
<p>I tried to cover most of the important steps here without getting too deep into the details.</p>
<p>If you have any questions or are interested in getting more in depth training or consulting on getting BATs setup for your environment, send me an email or leave a comment.</p>
<p>It can be a little difficult to get started and get a BAT framework up and running, but the rewards are well worth the effort!</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1329/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1329&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/05/14/getting-up-to-bat-building-a-true-dsl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/05/spinal_tap_but_it_goes_to_eleven_thumb.jpg" medium="image">
			<media:title type="html">spinal_tap_but_it_goes_to_eleven</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting up to BAT: Creating Your First Smoke Tests</title>
		<link>http://simpleprogrammer.com/2011/03/28/getting-up-to-bat-creating-your-first-smoke-tests/</link>
		<comments>http://simpleprogrammer.com/2011/03/28/getting-up-to-bat-creating-your-first-smoke-tests/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 23:15:11 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[BAT]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/03/28/getting-up-to-bat-creating-your-first-smoke-tests/</guid>
		<description><![CDATA[If you have been following my posts so far on Becoming Bat Man, you should already have hired an automation lead, figured out what browser driver you are going to use and come up with a design plan for your automation framework. Now you are probably faced with the difficult decision of… Where to begin [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1292&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have been following my posts so far on <a href="http://simpleprogrammer.com/2011/02/05/back-to-basics-becoming-bat-man/">Becoming Bat Man</a>, you should already have <a href="http://simpleprogrammer.com/2011/02/23/getting-up-to-bat-hiring-an-automation-lead/">hired an automation lead</a>, <a href="http://simpleprogrammer.com/2011/03/06/getting-up-to-bat-picking-a-browser-automation-tool/">figured out what browser driver you are going to use</a> and come up with a <a href="http://simpleprogrammer.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/">design plan for your automation framework</a>.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/03/smoking_computer.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="smoking_computer" border="0" alt="smoking_computer" src="http://complextosimple.files.wordpress.com/2011/03/smoking_computer_thumb.jpg?w=465&#038;h=471" width="465" height="471" /></a></p>
<p>Now you are probably faced with the difficult decision of…</p>
<h2>Where to begin with your tests</h2>
<p>I don’t suggest writing your automation framework first and then writing tests to use it.&#160; If you go this route you’ll have two problems</p>
<ol>
<li>It will be a long time and large investment before you see any fruits from your automation effort. </li>
<li>Your framework will likely be designed incorrectly or not test-writer friendly.&#160; (Which is basically the same as wrong.) </li>
</ol>
<p><strong>What you really want to do is to write some basic tests that let the development of those tests drive the development of your framework.</strong></p>
<p>The best tests to drive your framework are some basic “smoke tests.”&#160; If you are not familiar with the term “smoke test,” it basically means some tests that make sure the application you are testing is at least somewhat working and not completely broken.&#160; </p>
<p>There are a few different opinions of what exactly constitutes a smoke test, but in general, if you have any tests that you regularly run on a new build to make sure it is at least OK, those would be the tests we are interested in here.</p>
<p>You are going to want to start by taking the easiest and most simple tests you have and writing them in a concise syntax that you use to drive the development of your framework.</p>
<p>It is very important at this stage to not worry about what you think might be possible or how it would be implemented in the framework, but to instead focus and making the tests as terse and explanative as possible.</p>
<p>The basic idea is that you will write the test out in the syntax you would like to be able to use, then implement the framework features required to make that test pass.&#160; This whole process is very similar to doing Test Driven Development.</p>
<h2></h2>
<h2></h2>
<h2>An example case</h2>
<p>The easiest way to demonstrate this is with an example.</p>
<p>Let’s say you have a smoke test like the following:</p>
<p><em>Create a new account, pick an on-sale item, add it to your cart and check out using PayPal.&#160; Verify that we hit the order success page.</em></p>
<p>We might write a test for this that looks something like:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:835fd59d-5f61-4af6-ba64-04228d582e22" class="wlWriterEditableSmartContent">
<pre>
<pre class="brush: csharp; pad-line-numbers: true;">
Workflow.Users.CreateNewUser();
Pages.Login.LoginWithLastCreatedUser();
Pages.SaleItems.AddAnyToCart();
Workflow.Cart.CheckoutUsingPayPal();
Assert.True(Pages.Checkout.SuccessPage.IsAt());


</pre>
</pre>
</div>
<p>What I just wrote above is astonishingly simple.&#160; You are likely saying to yourself something along the lines of “What if… blah.”</p>
<p>Forget it!&#160; We’ll handle “what if” later.&#160; Right now we are going to write the tests as terse as possible and not handle any other conditions.</p>
<p>What I wrote above is the style that I like to write the tests in, which is highly subject to opinion, but the content of what I wrote is not as subjective.</p>
<p>There are a few important points to note:</p>
<ul>
<li>I used methods like <em>CreateNewUser</em>, <em>LoginWithLasteCreatedUser</em> and <em>CheckoutUsingPayPal</em> that do a huge amount of work and have no parameters.&#160; Why?&#160; Because for the purpose of this test, (and you’ll find for most of your tests), we don’t care about what the first name or last name or address of the user is, we don’t care how we get them logged in, and we only care that they checkout using PayPal, not what account is used, etc. </li>
<li>I didn’t declare any variables.&#160; Tests should be simple.&#160; Let the framework remember the state. </li>
<li>I over-simplified.&#160; This is fine, you are working inside of a very specific domain.&#160; Let your test framework methods do one large thing.&#160; Don’t worry about oversimplifying for now. </li>
<li>I asserted something at the end.&#160; All tests need to assert something.&#160; If you can’t figure out what to assert, work on redesigning the test before automating it. </li>
<li>I didn’t pass parameters.&#160; Avoid this also.&#160; <strong>This goes along with the first point, but is so important that I feel it is OK to state it twice.</strong>&#160; If you don’t care about variation, eliminate it.&#160; You will constantly need to find places where a manual tester would have to enter specific information, but an automated test won’t care what that information is. </li>
<li>All my methods are static.&#160; While this would be bad in normal production code, for a test API it is the easiest for test writers to use.&#160; No variable declarations, no “newing” up objects, no constructors, etc. </li>
<li>It’s written in “business language.” As close to the language an end user or business person would use to describe the test.</li>
</ul>
<p>So, this test is definitely doing a huge amount of stuff in a few lines of code, and because of this your inclination would be to say that the API level is too high. Don’t!</p>
<p>Instead, make the API level as high as you possibly can, until further tests you try to implement prove to you that it must be broken down further.</p>
<p>By working this way, you ensure a reduction in the total lines code and complexity of your tests by as much as possible.</p>
<p>You would NEVER work like this with normal code, but for automated tests this is essential.&#160; The main reason is because you will be calling the same methods perhaps 1000s of times, where in normal code you usually only reuse a method in a few places. </p>
<h2>Next steps</h2>
<p>For my example above, the next step would be going through and implementing all the framework methods required in order to make that test runnable.&#160; You will end up utilizing the general design you came up with for your automation framework to do this.</p>
<p>Then you will simply move on to the next test and repeat.&#160; Each time you should have less and less effort required, as more of the basic functionality of your automation framework is implemented.</p>
<p>Automating your smoke tests should ensure that you get a fairly even distribution of the framework code written as the smoke tests should cover many different areas of your software.</p>
<p>But, don’t start adding these smoke tests to your build yet.&#160; We’ll cover that in the next step.&#160; Adding them to the build prematurely can cause the confidence in these tests to be forever diminished!&#160; We don’t want to do that!</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1292&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/03/28/getting-up-to-bat-creating-your-first-smoke-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/03/smoking_computer_thumb.jpg" medium="image">
			<media:title type="html">smoking_computer</media:title>
		</media:content>
	</item>
		<item>
		<title>Guest Post: The Cross-Browser Compatibility Myth</title>
		<link>http://simpleprogrammer.com/2011/03/22/guest-post-the-cross-browser-compatibility-myth/</link>
		<comments>http://simpleprogrammer.com/2011/03/22/guest-post-the-cross-browser-compatibility-myth/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 02:57:59 +0000</pubDate>
		<dc:creator>hsonmez</dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[BAT]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://simpleprogrammer.com/?p=1277</guid>
		<description><![CDATA[This post is a special guest post from my wife, Heather Sonmez, who is an expert on the subject of blackbox automated tests and designing frameworks for them.  She has designed successful automation frameworks for several companies.  She deals with software automation and framework design issues on a daily basis, so I thought she might [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1277&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#00b050;font-size:small;"><span style="color:#00b050;font-size:small;"> </span></span><span style="color:#00b050;font-size:small;"><span style="color:#00b050;font-size:small;"><span style="color:#00b050;font-size:small;"><span style="color:#00b050;font-size:small;"> </span></span></span></span></p>
<div><em>This post is a special guest post from my wife, Heather Sonmez, who is an expert on the subject of blackbox automated tests and designing frameworks for them.  She has designed successful automation frameworks for several companies.  She deals with software automation and framework design issues on a daily basis, so I thought she might be able to offer some good insight on the topic.</em></div>
<div>
<p></div>
<div>
<p>John asked me to write a post based on my experience with writing automated tests.  I’ve been working as a QA Automation Engineer for the past three and a half years. During this time I have had the opportunity to work with Ruby/Watir, C#/Watin, and Java/Selenium RC. In thinking on a topic, I decided that there’s no time like the present to talk about what I’m presently facing, and would like to share some insight straight from the trench I currently find myself in today:</p>
</div>
<h2>Automation tools that claim to support multiple browsers are LYING</h2>
<p>Currently I am in the process of getting 400 automated tests that run in Firefox to run in Internet Explorer and Chrome. While the tests are using Selenium RC, a tool that claims to work on all three browser platforms, in actuality, many tests are failing and not for good reasons (bugs).</p>
<p>Here’s the rundown on what these overly-ambitious tools aren’t telling you:</p>
<ul>
<li>Xpath in Browser A isn’t always supported in Browser B</li>
<li>The Dom in Browser A may vary from the Dom in Browser B</li>
<li>Browser B may have built-in security settings that interfere with testing</li>
<li>Bugs in the automation tool itself may cause issues in specific browsers</li>
</ul>
<div><span style="font-size:20px;font-weight:bold;"><strong>The XPath Issue</strong></span></div>
<p>When it comes to XPath, I fully expected that any given expression was either valid or invalid. But it didn’t take more than one test run in Internet Explorer to suddenly find myself with tests that claimed certain elements didn&#8217;t exist. While Firefox accepted and successfully returned my element using the provided expression, IE claimed the expression itself was invalid. In this particular instance I discovered an issue with Selenium stripping off the end of my xpath statement, thus making it invalid.</p>
<p>But ultimately, whether it&#8217;s the browser or the tool doesn&#8217;t matter because the same expression is not working unequivocably in both browsers.</p>
<p><strong> </strong><strong> </strong></p>
<h2><strong>The Dom Issue</strong></h2>
<p>The next problem I immediately came across was the problem of Dom differences between browsers. In this particular case I had an element that occurred one time in Firefox but twice in IE. My test, expecting one instance of the element, failed. While I can’t tell you why this discrepancy exists (currently under investigation by some client-side engineers), I have a fair degree of confidence in saying this won’t be the last time I come across this issue.</p>
<p>In the quest to support many different browsers, it only follows that one is going to come across conditional browser logic, especially if a company is striving to support multiple browser versions (IE 6, 7, 8, 9). If a developer has to occasionally write browser-specific condition statements, it makes sense that we&#8217;d have to do the same to test specific browsers.</p>
<p><strong> </strong><strong> </strong></p>
<h2><strong>The Security Issue</strong></h2>
<p>If it seems that I’m picking on IE, it’s only because I can’t get very far in running our tests in Chrome. Chrome has special security settings that cause a Selenium exception if your test changes domains mid-run. This can easily be solved by passing a parameter to Chrome which will disable this security feature when the test runs, the trick is figuring out when/where/how to pass that parameter.</p>
<p><strong> </strong><strong> </strong></p>
<h2><strong>The Bug in the Tool Issue</strong></h2>
<p>Finally, the last obstacle I’ve come across in multi-browser testing: the tool itself. Any tool, regardless of how fabulous it is, is going to have bugs. Selenium RC has an issue where its select method (responsible for selecting a value in a dropdown menu) doesn’t trigger affiliated event handlers- in Internet Explorer. To work around this, one can manually call the event handler using Selenium’s runscript() but you will lose some degree of testing confidence in doing so (how do you know the event is really firing in response to a particular user action if you’re manually forcing it in automation?)</p>
<p>Another issue exists around multiple browser windows; if you need more than one open for your test, Selenium is unable to select the second window you open- another outstanding IE issue that has not been resolved.</p>
<p><strong> </strong><strong> </strong></p>
<h2><strong>Summary</strong></h2>
<p>In all fairness, some of these issues have more to do with the browsers themselves than with the automation tool. However, that makes it even more important to realize that when an automation tool says it supports multiple browsers, it’s not without some creativity, troubleshooting, legwork, and maintenance.</p>
<p>Knowing these kinds of issues exist is important in order to decide if and how much browser compatibility testing you want to automate. It&#8217;s definitely something to realize before deciding on a tool just because the tool claims to support other browsers.</p>
<p><strong>Just as there is no silver bullet for writing a web application that works in every browser imaginable, there is no silver bullet for automation either.</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1277/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1277/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1277/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1277&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/03/22/guest-post-the-cross-browser-compatibility-myth/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ec419ec8af10304b5129e246c0807c35?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">hsonmez</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Up to BAT: Designing an Automation Framework</title>
		<link>http://simpleprogrammer.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/</link>
		<comments>http://simpleprogrammer.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 00:01:36 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[BAT]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Functional]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/</guid>
		<description><![CDATA[Now that you’ve gotten an automation lead and decided on the browser automation tool you are going to use, the next step is to design an actual automation framework. This is one of the most critical components of the overall success of your automation strategy, so you will want to make sure you invest properly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1275&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now that you’ve gotten an automation lead and decided on the browser automation tool you are going to use, the next step is to design an actual automation framework.</p>
<p>This is one of the most critical components of the overall success of your automation strategy, so you will want to make sure you invest properly in this area.</p>
<p>I have seen a large number of automation projects go forth, but each time the critical component determining their success or failure was having a good automation framework.</p>
<p>Solid design and excellent technical resources are absolutely critical to success in this area!</p>
<h2>What is an automation framework?</h2>
<p>An automation framework is essentially an API that all of your BATs (Blackbox Automated Tests) are written against.</p>
<p>This API can be as simple as the API that is exposed by your browser automation tool (WatiN, Selenium, etc.), but I would highly recommend building your own layer on top of the browser automation tool’s API that will act as a DSL (Domain Specific Language) for automating your application.</p>
<p>Let me break this down a bit further by using an example.</p>
<p>Think about the task of making coffee.</p>
<p>There are several “API” levels we can interact with.</p>
<ol>
<li>We can go with a very low level API where we take whole coffee beans and grind them down.&#160; Then we take some water, get it hot.&#160; We take our filter put the ground beans in it, put it over a cup and pour the water into the filter.</li>
<li>We can go with a higher level API where we use a traditional coffee maker.&#160; In this case we load the coffee maker with a filter, ground coffee beans and water and push a “brew” button.&#160; We could also set it to start at a certain time.</li>
<li>We can go with a very high level API where we use a <a href="http://www.amazon.com/gp/product/B000AQSMPO/ref=as_li_ss_tl?ie=UTF8&amp;tag=makithecompsi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B000AQSMPO">Keurig</a> machine or similar device.&#160; In this case we only make sure the machine has water in it, and we just insert a little pod and press brew.&#160; We can make different kinds of coffee, cider or hot cocoa just by changing what pod we use.</li>
</ol>
<p><a href="http://complextosimple.files.wordpress.com/2011/03/unnamed.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="unnamed" border="0" alt="unnamed" src="http://complextosimple.files.wordpress.com/2011/03/unnamed_thumb.jpg?w=220&#038;h=220" width="220" height="220" /></a></p>
<p>Using the API provided by the browser driver is like making the coffee by hand.&#160; It’s going to take a large amount of effort each time you do it.</p>
<p>We want our automation framework to be more like the Keurig machine.&#160; We want to be able to compartmentalize our tests in little pods that are small and don’t require many hooks into the automation framework.</p>
<p>To rehash this one more time, basically our automation framework will be a framework we build on top of the browser driver framework, which is designed to make it easy to write tests which automate our application.</p>
<h2>What makes a good automation framework design?</h2>
<p><strong>The true measure of an automation framework is the size of the tests that are written against them. The less lines of code in each test, the better the automation framework captures the domain of the application being automated.</strong></p>
<p>In my <a href="http://simpleprogrammer.com/2010/01/05/automated-ui-testing-framework-a-real-example/">earlier post about an example of an automation framework</a>, I talked a bit about the strategy I used in a real implementation of an automation framework.</p>
<p>Here is a diagram showing the different layers.&#160; You can see the framework layer is in green here.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/03/automated_testing_framework-2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="automated_testing_framework-2" border="0" alt="automated_testing_framework-2" src="http://complextosimple.files.wordpress.com/2011/03/automated_testing_framework-2_thumb.png?w=482&#038;h=577" width="482" height="577" /></a></p>
<p>You can also see in this diagram that on the right hand side, I have screens, workflows and navigation.</p>
<p>This is one of the common design patterns you can use to build your automation framework, since it closely models that of most web applications.</p>
<p>A good way to design your framework is to use a pattern like this and create classes for each page in your application, create classes which might represent workflows in your application, and create some classes for navigating around the application.</p>
<p>The basic idea you are shooting for with your automation framework is to make it so the tests do not have to know anything about the browser.&#160; Only your automation framework itself should be dealing with the DOM and HTML and CSS.&#160; Your tests should be dealing with concepts which any user would be familiar with.&#160; That is why I commonly use pages and workflows.</p>
<p>Let me give you an example.</p>
<p>Let’s say we ignored the advice of creating an automation framework and decided to program our tests directly against the browser driver layer.&#160; In this case, let’s say that we want to automate a login page.&#160; Our test might look something like this pseudo-code.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:af0bdb44-e0ca-4c0b-94d6-200830b1ed71" class="wlWriterEditableSmartContent">
<pre>
<pre class="brush: csharp; pad-line-numbers: true;">
browser.goto(&quot;http://mywebsite/login.aspx&quot;);
Element userName = browser.getElementById(&quot;login_userName&quot;);
userNameTextField.Type(&quot;Joe&quot;);

Element userPassword = browser.getElementById(&quot;login_userPassword&quot;);
userPassword.TextField.Type(&quot;mypassword&quot;);

Element loginButton = browser.
    getElementByXPath(&quot;//button[class=&quot;loginButton&quot;]&quot;);
loginButton.Click();
</pre>
</pre>
</div>
<p>&#160;</p>
<p>This is not very readable.&#160; It is not something an average tester will be able to pick up and start writing, and it is extremely fragile.&#160; If you have 500 tests like this and the id changes for one of the elements on the page, many tests will break.</p>
<p>Now, contrast it to this pseudo-code:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:a727af81-9910-4280-bab2-a5da7a354e0d" class="wlWriterEditableSmartContent">
<pre>
<pre class="brush: csharp;">
Pages.Login.Goto();
Pages.Login.LoginWithDefaultUser();
</pre>
</pre>
</div>
<p>&#160;</p>
<p>Where did all the code go?&#160; You don’t need it!&#160; Actually it went into the framework, where it can be reused.&#160; Now your test code is simple, can be understood by just about anyone, and won’t break with changes to the UI.&#160; (You will just have to change the framework method instead of 500 tests.)</p>
<p>If you want some more detailed examples take a look at my Boise Code Camp slides on the subject <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing">here</a>.</p>
<p>Let me offer up some general guidelines for creating a good design for an automation framework.</p>
<ol>
<li>NEVER require the tests to declare variables.</li>
<li>NEVER require the tests to use the <em>new</em> keyword or create new objects.</li>
<li>NEVER require the tests to manage state on their own.</li>
<li>ALWAYS reduce the number of parameters for API calls when possible.</li>
<li>ALWAYS use default values instead of requiring a parameter when possible.</li>
<li>PREFER to make the API easier to use over making the internals of the API less complex.</li>
<li>PREFER using enumerations and constants to requiring the test to pass in primitive types.&#160; (Make the input bounded when possible.)</li>
<li>NEVER expose the browser or DOM to the tests or let them manipulate it directly.</li>
</ol>
<p>You can see that these guidelines will almost force your API to be entirely static methods!&#160; Don’t freak out.&#160; It is perfectly fine.&#160; There is nothing wrong with using static methods in this case.</p>
<p>Stop… take a breath, think about why you think static methods are bad, because <a href="http://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/">I probably agree with you.</a></p>
<p>But, in this case we are HIGHLY valuing making the tests simple and easy to write over anything else, and because of this emphasis, static methods are going to be the way to go.</p>
<h2>Some advice on getting started</h2>
<p>Start with the tests in plain human English.</p>
<p>Take those tests and make them into code preserving as much English as possible.&#160; Then work down from there implementing the methods needed to make those tests work.&#160; Only add things as you need them.&#160; Do not overdesign!</p>
<p>In my example above, we might have started with something like this:</p>
<p>1. Goto the login page.</p>
<p>2. Login with the default user.</p>
<p>The actual code looks just like that.&#160; It should always be a 1 to 1 mapping.</p>
<p>This is where having someone that has some experience doing this is going to come in handy.</p>
<p>Just keep in mind the whole time your 2 big goals:</p>
<ol>
<li>Easy to write tests</li>
<li>Tests are concise</li>
</ol>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1275/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1275&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/03/16/getting-up-to-bat-designing-an-automation-framework/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/03/unnamed_thumb.jpg" medium="image">
			<media:title type="html">unnamed</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/03/automated_testing_framework-2_thumb.png" medium="image">
			<media:title type="html">automated_testing_framework-2</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Up to BAT: Hiring an Automation Lead</title>
		<link>http://simpleprogrammer.com/2011/02/23/getting-up-to-bat-hiring-an-automation-lead/</link>
		<comments>http://simpleprogrammer.com/2011/02/23/getting-up-to-bat-hiring-an-automation-lead/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 05:03:39 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[BAT]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Interview]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/02/23/getting-up-to-bat-hiring-an-automation-lead/</guid>
		<description><![CDATA[This is my first in a series of posts about getting to fully automated blackbox testing, or BAT, as I like to call it. In my last post in the Back to Basics series, I mentioned that I would begin this series with the intent of showing you step by step how to go from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1264&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is my first in a series of posts about getting to fully automated blackbox testing, or BAT, as I like to call it.</p>
<p>In my <a href="http://simpleprogrammer.com/2011/02/05/back-to-basics-becoming-bat-man/">last post in the Back to Basics series</a>, I mentioned that I would begin this series with the intent of showing you step by step how to go from no automation to a quality BAT infrastructure.</p>
<p>By the end of this series you should have the information you need to actually get automated testing going in your organization instead of just talking about it.</p>
<p>First stop on this train is hiring an automation lead.</p>
<h2>Don’t doom yourself before you start</h2>
<p>If you think you are going to create BATs, but you are not going to have at least 1 dedicated resource to doing the job of getting this all going, you are probably bound for failure.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/02/doom4.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="DOOM4" border="0" alt="DOOM4" src="http://complextosimple.files.wordpress.com/2011/02/doom4_thumb.jpg?w=474&#038;h=452" width="474" height="452" /></a></p>
<p><strong>Listen up, because this is the single biggest mistake that most organizations make when trying to get BATs up.</strong></p>
<p>This mistake is thinking that you can get your QA team to get this going and you can part time some developers onto the project, but not having a dedicated resource.</p>
<p>Why is this absolutely absurd and you should expect it to fail?&#160; Because, in order to get an infrastructure to support your BATs, you are going to need to basically design and create a testing framework that is tailored to the business domain of your application.</p>
<p>Blah, what?&#160; Ok, in simple terms.&#160; Someone is going to need to design and build an automation framework.</p>
<p>If you think you are just going to buy some tool and use it to record test scripts, you are wrong.&#160; That approach simply is not going to work.&#160; I won’t get into why here, but I have <a href="http://simpleprogrammer.com/2009/12/18/automated-functional-testing-record-or-program/">written on it before in the past</a>, and if you are interested, let me know and I’ll go much more in depth.</p>
<p>Think about this, do you want your QA team, as good as they may be at QA work, designing and building an automation framework?&#160; Give them a few C# or Java classes and have their first real coding work be to design a complex system?</p>
<p>How about a developer who has “real” work and can only devote part time to designing what may end up becoming one of the most important parts of your infrastructure?</p>
<p>It is fine to pull a developer off of the main product and put them in this role until it is up and running, but make no mistake, you need a dedicated resource.</p>
<p>You are going to want to a well designed maintainable automation framework, because the ease of use of that framework will determine how easy or not it is to write automated tests that use that framework.</p>
<h2></h2>
<h2>I recommend getting someone who has done it before</h2>
<p>Why?&#160; Because creating an automation framework is much different than developing your software and it is much different than writing tests.&#160; It really requires a special skill set that is not so easily acquired without the experience of having done this before.</p>
<p>I also think it is fine to use a developer resource, but if you do, you want to try to get a more senior developer to take this role.</p>
<p>Here is a list of some of the skills that I think are important which may also make it much more clear why I am recommending a specialist in this case:</p>
<p><strong>Development of APIs</strong> (In the end the automation framework will be an API that is used to write automated tests.&#160; The better the API is designed, the easier it will be to write tests against it.)</p>
<p><strong>Design of reusable base components</strong> (Much of the framework consists of repeated concepts with different variations for different screens in your application.&#160; As a result, the core of the framework will be a basic design that allows for variation without too much repetition… reuse)</p>
<p><strong>Ability to quickly acquire domain knowledge of the software</strong> (Someone writing an automation framework needs to really understand how the system under test works, so that they can model the framework after it.)</p>
<p><strong>Pragmatism</strong> (Many “accepted” good software designs are actually bad automation framework designs.&#160; Static methods can make an automation framework’s API much more simple to use, especially for non-programmers, but would not be a good design choice in your main product.&#160; A person who designs an automation framework should be pragmatic enough to “break the rules” in order to make the framework easiest to use and maintain.)</p>
<p><strong>Experience or understanding of QA</strong> (It is important to understand the users of the framework, the QA team.&#160; Understanding what kind of tests they will likely write or how they will think will go a long way in coming up with a good framework design.)</p>
<p><strong>Communication skills</strong> (Good BATs read like English.&#160; It is critical to make sure that the person designing the framework facilitates this to make the BATs as useful and understandable as possible.)</p>
<p><strong>HTML / XPath </strong>(This specific skill set is very important for web based products.&#160; Creating an automation framework built on top of one of the web browser drivers will require intimate knowledge of HTML and probably XPath to be able to access attributes and elements on pages in your application.)</p>
<p>I’ve written a few automation frameworks and contributed to the design of several others, and I can tell you that my version 6.0 of an automation framework was much much better than version 1.0.</p>
<p>There are a huge number of patterns that emerge that are unique to this problem domain.&#160; So, I do believe having experience in this area specially is a huge benefit.</p>
<h2></h2>
<h2></h2>
<h2>What does this automation person do?</h2>
<p>We’ll get to more specific in my later posts in this series, but the basic responsibility should be:</p>
<ul>
<li>Figure out the technology and tools to be used</li>
<li>Create the initial automation framework</li>
<li>Create smoke tests for the application under test</li>
<li>Get those smoke tests into some kind of automated build</li>
<li>Train developers and QA in the use of the framework</li>
<li>Drive the adoption of the framework and automation for all features</li>
<li>Set up rules for consistency in writing automated tests</li>
<li>Design of hierarchy and structure of automated tests</li>
</ul>
<p>You want your automation person to be responsible for pushing and driving forward the goal of getting to the point of being able to automate each feature being created with minimal effort.</p>
<p>This is one of those jobs that can actually be “done.”&#160; What I mean by that is you may have the automation lead end up creating the framework, developing it enough to push it out to your development teams and train them to write automated tests along with QA, and you really don’t need an automation lead anymore.</p>
<p>This is great though, because now you have a developer that really knows your product and is a good bridge to QA, or you can keep them improving the framework and overseeing it if you want to go that route.</p>
<p>Bottom line is:</p>
<ol>
<li>Make sure you get a dedicated resource</li>
<li>Make sure that resource can write code and design a framework</li>
<li>Make sure they train everyone else, one person cannot automate your entire application</li>
</ol>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1264/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1264&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/02/23/getting-up-to-bat-hiring-an-automation-lead/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/02/doom4_thumb.jpg" medium="image">
			<media:title type="html">DOOM4</media:title>
		</media:content>
	</item>
		<item>
		<title>Objective-C Here I Come!</title>
		<link>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/</link>
		<comments>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 02:39:50 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1244</guid>
		<description><![CDATA[Have I blabbed enough about the PaceMaker app I released for Android yet? First month of sales are over, and it was much better than I had expected.  About 75 purchases in the first 30 days.  Not a huge amount, but that is almost with no advertising, most people who found the app found it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1244&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have I blabbed enough about the <a href="http://simpleprogrammer.com/2011/01/04/introducing-pacemaker-for-android/">PaceMaker</a> app I released for Android yet?</p>
<p>First month of sales are over, and it was much better than I had expected.  About 75 purchases in the first 30 days.  Not a huge amount, but that is almost with no advertising, most people who found the app found it in the market.</p>
<p>So what is the next step for PaceMaker?</p>
<p>Well, with the <a href="http://support.vzw.com/faqs/iphone/iphone_faq.html">iPhone coming to Verizon this month</a>, I think it is pretty obvious that it is time for the iPhone version.</p>
<p>Only problem is…</p>
<h2>I know nothing about iPhone development!</h2>
<p>Well I didn’t last week, but I am slowly learning.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/02/iphone.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="iphone" src="http://complextosimple.files.wordpress.com/2011/02/iphone_thumb.jpg?w=204&#038;h=370" border="0" alt="iphone" width="204" height="370" /></a></p>
<p>I bought my first Mac ever last week, a <a href="http://www.amazon.com/gp/product/B00487X27O?ie=UTF8&amp;tag=makithecompsi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B00487X27O">MacBook Air</a>.</p>
<p>I have to say, the operating system on Macs has come a long way since I last used one.  (Did I mention I also don’t even know how to properly run a Mac?  But I know Unix, so I should be ok.)</p>
<p>I feel like the Mac interface is so much more polished and uniform than Windows, but it is pretty scary inside when you consider all the low level C and Objective C code.</p>
<p>Then again you have to consider that the wonderful .NET CLR is written right on top of a really crusty win32 API layer which is a bunch of scary C code that is about 20 years old.</p>
<p>So I am setting out on a brave new quest to learn Mac, iPhone and Objective-C and somehow port my application over to the platform.</p>
<h2>Objective-C is kind of like an alternate universe</h2>
<p>I was trying to think how I would describe Objective-C and here is what I came up with:</p>
<blockquote><p>Objective-C is like one of those movies where there is an alternate universe where the same people exist as in this universe, but in some areas their technology is really advanced, but in others it’s really ancient.  Like a bunch of people flying around in flying cars, but their weapons are still bows and arrows.</p></blockquote>
<p>I used to be a C++ programmer, so not too many things scare me, but some of the magical constructs in Objective-C are very frightening indeed.</p>
<p>I was just reading about a strange construct today that allow you to basically create the equivalent of a C# interface, but in Objective-C it is called a “Protocol.”  This seems fine and normal until I read the paragraph that says you can define some of the methods as “Optional.”  What?</p>
<p>Let me put it in C# terms so you can understand it.  In C# it would look like this:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:60464cb2-395c-47e9-9ed3-a55df9c8a2e5" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: csharp; pad-line-numbers: true;">
public interface ILovePuppies
{
   private void HugThem();
   private void SqueezeThem();

   perhaps Corpse KillThem(); // Implement this one
                              //only if you feel like it.

}
</pre></p>
</div>
<p>This is not a joke.  I still can’t quite figure out what this is for, but it is kind of interesting.</p>
<p>Another thing I found interesting is Objective-C has this thing called a “Selector.”  It is not a function pointer, it is a variable that references the name of a method.</p>
<p>How is this different than a function pointer?</p>
<p>It is actually the name of the method being referenced.  So if you have a class Dog that has a method “Wag” and you have a class WildGuesser who has a method “Wag”, passing them the “Wag” selector will cause very different results.  How bizarre.</p>
<h2>It’s weird to get sucked into the Mac world</h2>
<p>It’s actually kind of funny.  Here were all us Java and C# programmers off basically doing the same thing; creating our interfaces and arguing about dependency injection and mocking our unit tests and these Mac geeks with their bow ties and designer jeans were going a totally different direction.</p>
<p>It was only by random chance that our two parallel universes should violently collide.  The iPhone came out and suddenly all these strange “Mac boys” were teaching us this new old language and reminding us to free up own memory again.</p>
<p>FOR GOD&#8217;S SAKE I JUST IMPORTED A C HEADER FILE FOR THE FIRST TIME IN 10 YEARS!  THIS IS CRAZY!</p>
<p>But, I have to admit it is actually kind of fun.</p>
<h2>Sometimes a change of pace is refreshing</h2>
<p>I don’t mean my harsh language to be derogatory towards you Mac heads out there.  You know you are cool, your boy Steve is leading this century&#8217;s computing revolution.</p>
<p>I honestly mean that.  Good job guys, you may just take over the world.</p>
<p>I’m actually enjoying this experience and beginning to think that if I come out alive, I will have gained some very valuable insights into programming in C# and Java.  It is good sometimes to view something from a totally completely different perspective.</p>
<p>Who knows maybe I’ll get to write that Objective-C vs Java vs C# post I&#8217;ve been dreaming of.</p>
<p>But what about…</p>
<h2>MonoTouch?</h2>
<p>Meh.  If I am going to program for a platform, I am going to program for that platform.  I’m not going to half learn how to program for the iPhone and learn on the C# crutch.  I didn’t do that for Android and I’m not going to do it for iPhone either.</p>
<p>Why?</p>
<p>Because I am stubborn and cranky?  Partially, but I actually have a few sensible reasons also:</p>
<ol>
<li><a href="http://monodroid.net/">MonoDroid</a> and <a href="http://monotouch.net/">MonoTouch</a> both implement another layer over the phone’s framework.  Adding this additional layer makes it harder to do low level stuff, and with something as low level as a phone, doing low level stuff is often important.</li>
<li>You are still using the underlying framework for either Android or iPhone.  It is not like using C# code behind the scenes allows you to write a Silverlight UI that you can use on any of the mobile platforms.  You still have to learn the entire phone development framework, which dovetails into point three…</li>
<li>It is much easier to get help and find resources for raw Android or iPhone development than for MonoX development.  Not trying to bash the Mono projects here, but most of mobile programming is spent googling for how to do things.  By sticking with C# you are really limiting yourself in terms of finding answers.</li>
<li>Change and learning different things is good.  I’m not sure you can fully appreciate the design of a framework or platform unless you develop against it the way it was designed.  I could be wrong, but I think there is a potential “lost in translation” problem in using C# on the iPhone or Android platforms.</li>
</ol>
<p>After I learn iPhone development, I might try MonoTouch and see if it makes my life easier, but I need a good baseline first.</p>
<p>Well, I’m off on my journey.  Going to head on to the back of the wardrobe in the “Spare-Oom.”  I have to meet Mr. Tumnus, we are having tea with Mr. Wozniak and Mr. Jobs.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/02/mrtumnus.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="mrtumnus" src="http://complextosimple.files.wordpress.com/2011/02/mrtumnus_thumb.jpg?w=462&#038;h=478" border="0" alt="mrtumnus" width="462" height="478" /></a></p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1244/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1244&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/02/iphone_thumb.jpg" medium="image">
			<media:title type="html">iphone</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/02/mrtumnus_thumb.jpg" medium="image">
			<media:title type="html">mrtumnus</media:title>
		</media:content>
	</item>
		<item>
		<title>Back to Basics: Unit Testing, Automated Blackbox Testing, and Conclusions!</title>
		<link>http://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/</link>
		<comments>http://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 14:24:50 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Functional]]></category>
		<category><![CDATA[Process Improvement]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[User]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/</guid>
		<description><![CDATA[If you’ve been following me from the beginning of the Back to Basics series, you’ll know that I set out to reevaluate some of the commonly held truths of what best practices are, especially in regards to unit testing, dependency injection and inversion of control containers. We’ve talked about what an interface is, cohesion and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1225&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you’ve been following me from the <a href="http://simpleprogrammer.com/2010/10/30/getting-back-to-basics-introduction-and-why/">beginning</a> of the <a href="http://simpleprogrammer.com/back-to-basics-series/">Back to Basics series</a>, you’ll know that I set out to reevaluate some of the commonly held truths of what best practices are, especially in regards to unit testing, dependency injection and inversion of control containers.</p>
<p>We’ve talked about <a href="http://simpleprogrammer.com/2010/11/02/back-to-basics-what-is-an-interface/">what an interface</a> is, <a href="http://simpleprogrammer.com/2010/11/04/back-to-basics-cohesion-and-coupling-part-1/">cohesion and coupling</a>, and even went a little bit off track to talk about <a href="http://simpleprogrammer.com/2010/12/07/back-to-basics-sorting/">sorting</a> for a bit.</p>
<p>One of the reoccurring themes that kept showing up in most of the posts was unit testing.&#160; I talked about <a href="http://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/">why unit testing is hard</a>, and I defined three levels of unit testing.</p>
<ul>
<li><strong>Level 1</strong> &#8211; we have a single class with no external dependencies and no state.&#160; We are just testing an algorithm.</li>
<li><strong>Level 2</strong> &#8211; we have a single class with no external dependencies but it does have state.&#160; We are setting up an object and testing it as a whole.</li>
<li><strong>Level 3</strong> &#8211; we have a single class with at least one external dependency, but it does not depend on its own internal state.</li>
<li><strong>Level 4</strong> &#8211; we have a single class with at least one external dependency and depends on its own internal state.</li>
</ul>
<p>Throughout this series I ended up tearing down using interfaces with only single non-unit test implementation.&#160; I criticized the overuse of dependency injection for the sole purpose of unit testing.&#160; I attacked a large portion of best practices that I felt were only really being used in order to be able to unit test classes in isolation.</p>
<p>But, I never offered a solution.&#160; I told you what was bad, but I never told you what was good.</p>
<p>I said don’t create all these extra interfaces, use IoC containers all over your app, and mocks everywhere just for the purpose of being able to isolate a class you want to unit test, but when you asked me what to do instead, I said “I don’t know, I just know what we are doing is wrong and we need to stop.”</p>
<p>Well, that is no answer, but I intend to give one now.&#160; I’ve been thinking about this for months, researching the topic and experimenting on my own.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/01/cool-experiment.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="cool experiment" border="0" alt="cool experiment" src="http://complextosimple.files.wordpress.com/2011/01/cool-experiment_thumb.jpg?w=488&#038;h=390" width="488" height="390" /></a></p>
<h2>I finally have an answer</h2>
<p>But, before I give you it, I want to give you a little background on my position on the subject matter.</p>
<p>I come from a pretty solid background of unit testing and test driven development.&#160; I have been preaching both for at least the last 7 years.</p>
<p>I was on board from the beginning with dependency injection and IoC containers.&#160; I had even rolled my own as a way to facilitate isolating dependencies for true unit tests.</p>
<p>I think unit testing and TDD are very good skills to have.&#160; I think everyone should learn them.&#160; TDD truly helps you write object oriented code with small concentrated areas of responsibility.</p>
<p>But, after all this time I have finally concluded, for the most part, that unit tests and practicing TDD in general do more good for the coder than the software.</p>
<p>What?&#160; How can I speak such blasphemy?</p>
<p>The truth of the matter is that I have personally grown as a developer by learning and practicing TDD, which has lead me to build better software, but not because the unit tests themselves did much.&#160; </p>
<p>What happened is that while I was feeling all that pain of creating mocks for dependencies and trying to unit test code after I had written it, I was learning to reduce dependencies and how to create proper abstractions.&#160; </p>
<p>I feel like I learned the most when the IoC frameworks were the weakest, because I was forced to minimize dependencies for the pain of trying to create so many mocks or not being able to unit test a class in isolation at all.</p>
<p>I’ve gotten to the point now where two things have happened:</p>
<ol>
<li>I don’t need the TDD training wheels anymore.&#160; I don’t pretend to be a coding god or demi-god of some sort, but in general the code I write that is done in a TDD or BDD style is almost exactly the same as the code I write without it.</li>
<li>The IoC containers have made it so easy to pass 50 dependencies into my constructor that I am no longer feeling the pain that caused my unit tests to cause me to write better code.</li>
</ol>
<p>What I find myself ending up with now when I write unit tests is 70% mocking code that verifies that my code calls certain methods in a certain order.</p>
<p>Many times I can’t even be sure if my unit test is actually testing what I think it is, because it is so complex.</p>
<h2>Umm, did you say you had an answer, dude?</h2>
<p>Yes, I do have an answer.&#160; I just wanted to make sure you understand where I am coming from before I throw out all these years of practical knowledge and good practices.</p>
<p><strong>I am not the enemy.</strong></p>
<p>My answer to the problem of what to do if you shouldn’t be using IoC containers and interfaces all over your code base just for the purpose of unit testing, is to take a two pronged approach.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/01/2prong.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="2prong" border="0" alt="2prong" src="http://complextosimple.files.wordpress.com/2011/01/2prong_thumb.jpg?w=480&#038;h=480" width="480" height="480" /></a></p>
<ol>
<li>Mostly only write level 1 or level 2 unit tests.&#160; Occasionally write level 3 unit tests if you only have 1 or possibly 2 dependencies.&#160; (I’ll talk about more how to do this in my next post)</li>
<li>Spend a majority of your effort, all the time you would have spent writing unit tests, instead writing what I will call blackbox automated tests or BATs.&#160; (I used to call this automated functional tests, but I think that name is too ambiguous.)</li>
</ol>
<p>I intend to drill really deep into these approaches in some upcoming posts, but I want to briefly talk about why I am suggesting these two things in place of traditional BDD or TDD approaches.</p>
<h2>What are the benefits?</h2>
<p><strong>The first obvious benefit is that you won’t be complicating your production code with complex frameworks for injecting dependencies and other clever things that really amount to making unit testing easier.</strong></p>
<p>Again, I am not saying you shouldn’t ever use dependency injection, interfaces or IoC containers.&#160; I am just saying you should use them when they provide a real tangible value (which most of the time is going to require alternate non-unit test implementations of an interface.)</p>
<p>Think about how much simpler your code would be if you just went ahead and new’d up a concrete class when you needed it.&#160; If you didn’t create an extra interface for it, and then pass it in the constructor.&#160; You just used it where you needed it and that was that.</p>
<p><strong>The second benefit is that you won’t spend so much time writing hard unit tests.</strong>&#160; I know that when I am writing code for a feature I usually spend at least half the amount of time writing unit tests.&#160; This is mostly because I am writing level 3 and level 4 unit tests, which require a large number of mocks.</p>
<p>Mocks kill us.&#160; Mocking has a negative ROI.&#160; Not only is creating them expensive in terms of time, but it also strongly couples our test classes to the system and makes them very fragile.&#160; Plus, mocking adds huge amounts of complexity to unit tests.&#160; Mocking usually ends up causing our unit test code to become unreadable, which makes it almost worthless.</p>
<p>I’ve been writing mocks for years.&#160; I know just about every trick in the book.&#160; I can show you how to do it in Java, in C#, even in C++.&#160; It is always painful, even with auto-mocking libraries.</p>
<p>By skipping the hard unit tests and finding smart ways to make more classes only require level 1 and level 2 unit tests, you are making your job a whole lot easier and maximizing on the activities that give you a high ROI.&#160; Level 1 and level 2 unit tests, in my estimation, give very high ROIs.</p>
<p><strong>The thirds benefit is that blackbox automated tests are the most valuable tests in your entire system and now you’ll be writing more of them.&#160; </strong>There are many names for these tests, I am calling them BATs now, but basically this is what most companies call automation.&#160; Unfortunately, most companies leave this job to a QA automation engineer instead of the development teams.&#160; Don’t get me wrong, QA automation engineers are great, but there aren’t many of them, good ones are very expensive, and the responsibility shouldn’t lie squarely on their shoulders.</p>
<p>BATs test the whole system working together.&#160; BATs are your automated regression tests for the entire system.&#160; BATs are automated customer acceptance tests and <strong>the ROI for each line for code in a BAT can be much higher than the ROI of each line of production code.</strong></p>
<p>Why?&#160; How is this even possible?&#160; It’s all about leverage baby.&#160; Each line of code in a BAT may be exercising anywhere from 5 to 500 lines of production code, which is quite the opposite case of a unit test where each line of unit test code might only be testing a 1/8th or 1/16th a line of production code on average (depending on code coverage numbers being reached.)</p>
<p>I’ll save the detail for later posts, but it is my strong opinion that a majority of a development teams effort should be put in BATs, because BATs</p>
<ul>
<li>Have high value to the customer</li>
<li>Regression test the entire system</li>
<li>Have a huge ROI per line of code (if you create a proper BAT framework)</li>
</ul>
<p>Imagine how much higher quality your software would be if you had a BAT for each backlog item in your system which you could run every single iteration of your development process.&#160; Imagine how confident you would be in making changes to the system, knowing that you have an automated set of tests that will catch almost any break in functionality.</p>
<p>Don’t you think that is worth giving up writing level 3 and level 4 unit tests, which are already painful and not very fun to begin with to achieve?</p>
<p>In my future posts on the Back to Basics series, I will cover in-depth how to push more of your code into level 1 and level 2 unit tests by extracting logic out to separate classes that have no dependencies, and I will talk more about BATs, and how to get started and be successful using them.&#160; (Hint: you need a good BAT framework.)</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1225&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/01/cool-experiment_thumb.jpg" medium="image">
			<media:title type="html">cool experiment</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/01/2prong_thumb.jpg" medium="image">
			<media:title type="html">2prong</media:title>
		</media:content>
	</item>
		<item>
		<title>Back To Basics: Sorting</title>
		<link>http://simpleprogrammer.com/2010/12/07/back-to-basics-sorting/</link>
		<comments>http://simpleprogrammer.com/2010/12/07/back-to-basics-sorting/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 01:33:28 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2010/12/07/back-to-basics-sorting/</guid>
		<description><![CDATA[Why is sorting so hard? One of the most common misunderstandings and frustrations I see from developers is around sorting. Almost every developer has faced needing to sort a list of things in some manner in their development careers.&#160; Many developers end up fumbling through it, looking for an example from the web and then [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1190&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Why is sorting so hard?</p>
<p>One of the most common misunderstandings and frustrations I see from developers is around sorting.</p>
<p>Almost every developer has faced needing to sort a list of things in some manner in their development careers.&#160; Many developers end up fumbling through it, looking for an example from the web and then copying that example, not really knowing what they did or why it works.</p>
<p>If you fall into that category, or just want to know a little better how sort works, stay tuned, we are going to make it simple.</p>
<p><a href="http://complextosimple.files.wordpress.com/2010/12/harry-potter-sorting-hat.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="harry-potter-sorting-hat" border="0" alt="harry-potter-sorting-hat" src="http://complextosimple.files.wordpress.com/2010/12/harry-potter-sorting-hat_thumb.jpg?w=477&#038;h=310" width="477" height="310" /></a></p>
<h2></h2>
<h2>Sorting algorithms?</h2>
<p>Nope.</p>
<p>Great for computer science.&#160; You should have a basic idea of how they work, but unless you are writing some low level bit twiddling code on an integrated circuit, you don’t need to know about them.</p>
<p>Let’s think of sorting algorithms as a black box.&#160; You don’t need to know what the algorithm is or how it works, you just need to know that if you give the two things it requires it will sort your list for you.</p>
<p><strong>What two things do all sorting algorithms, regardless of implementation need?</strong></p>
<ol>
<li>A list of things to sort</li>
<li>A method to call to tell if object A comes before or after object B, or whether they are the same.</li>
</ol>
<p>That is all you need to know and give to a sorting algorithm implementation and it will do the rest.</p>
<p>Every modern programming language has at least one sorting algorithm and every single one of them has the exact two same inputs I mentioned above, a list to sort, and a comparison method.</p>
<p>It doesn’t matter if you are using C#, Java, Ruby or some other language, they all implement a sorting algorithm and need those two things.&#160; And that is all they need from you.</p>
<p>The burden is off your shoulders.</p>
<h2>Step 1: Find the sorting method</h2>
<p>I’m going to do better than teach you how to sort in each language.&#160; I’m going to show you how to figure out how to sort in a language.</p>
<p>The first step in doing that regardless of the language, is to find the method that sorts things.</p>
<p>A good place to look is the list or collection object itself, since that is the most obvious place to put a sort routine.</p>
<p>When we look up <a href="http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx">List</a> in C#, sure enough we find Sort on there.</p>
<p>Oh noes!&#160; So confusing!&#160; It has 3 sort methods!&#160; Which one do I call?&#160; Agh!</p>
<p>Don’t panic.&#160; Remember what I said above.&#160; Even though you see three signatures for the sort method, sort methods still only need two things.</p>
<p><em>Sort(), Sort(Comparison&lt;T&gt;), and Sort(IComparer&lt;T&gt;)</em> still need just a list and a method to compare two of your objects.</p>
<p>We’ll dive into that more in a bit, now let’s look at Java.</p>
<p>If we look up <em>ArrayList</em> in Java, we don’t find a sort method.&#160; Boo.&#160; What were they thinking.&#160; It’s ok though, googling for “Java sort” turns up <em>Arrays.sort</em> and <em>Collections.sort</em>.</p>
<p>Let’s look at <em>Collections.sort</em>.</p>
<p>This time we see two sort methods,<em> sort(List list),</em> and <em>sort(List list, Comparator c)</em>.</p>
<p>Again, nothing to be afraid of since we know the two things all sorting algorithms require from us.</p>
<h2></h2>
<h2>Step 2: Find the two things</h2>
<p>So if every sorting method needs the same two things from you, then all you need to do is figure out how to give it those two things.</p>
<p>In the C# and Java instances above, the first thing (the list of things to sort) is fairly obvious.&#160; In C# we saw that the sort method was on the list class itself, so we don’t even need to pass it the list of things to sort, it still needs it, but it knows where to find it.</p>
<p>In the Java instance the first parameter to both sort methods is a list.</p>
<p>See how easy we just made things?&#160; We are already 50% there.</p>
<p>So really the only question left is how to provide the method that compares two of our objects.</p>
<p><strong>When we know what we are looking for, it is much easier to find and understand.</strong></p>
<p>Let’s break down each instance and figure this out.</p>
<p>If we look at C#’s <em>Sort()</em> method, without reading the documentation, we can probably guess two things.</p>
<ol>
<li>The list to sort is the list we are calling the sort method on.</li>
<li>The objects in the list provide the comparing method.</li>
</ol>
<p>The first is obvious.&#160; The second one is a little less obvious, but if you think about it, since the method takes no parameters the only possible thing that could be providing the method for comparison is the objects in the list.</p>
<p>If we look at the <a href="http://msdn.microsoft.com/en-us/library/b0zbh7b6.aspx">documentation</a> for Sort(), we find that is true.&#160; The objects in the list have to implement <em>IComparable</em>.&#160; <em>IComparable</em> has one method, <em>CompareTo</em>, which takes one object and compares it to the other.&#160; If you implement this interface on your object, you can sort a list of them.&#160; Simple.</p>
<p>For <em>Sort(Comparison&lt;T&gt;)</em>, we can easily deduce that what is passed in there must be the method to compare two objects, and sure enough it is.&#160; If we want to use this method we just pass in a method of type <em>Comparison&lt;T&gt;</em> where T is the type of object we want to compare.</p>
<p>We can see that <em>Comparison&lt;T&gt;</em> is just a method that takes two of your objects and returns an int to indicate which is greater or if they are equal (1 = greater, 0 = equal, –1 less).</p>
<p>The final C# <em>Sort(IComparer&lt;T&gt;)</em> just takes an object that implements <em>IComparer&lt;T&gt;</em>.&#160; Sure enough, <em>IComparer&lt;T&gt;</em> has one method that must be implemented, Compare.&#160; That method has the same signature as <em>Comparison&lt;T&gt;</em> from above.</p>
<p>Now, let’s look at Java.&#160; You’re going to find it is pretty much the same thing.</p>
<p>For <em>sort(List list)</em>, we can easily see that the list to sort is passed in as a parameter, but once again we have to find where we supply the method to compare two of our objects.</p>
<p>Since it can’t be passed in, it must be… say it with me… on the object.&#160; That is right!</p>
<p>Turns out we just have to have our objects implement <em>Comparable</em> and then they can be sorted.&#160; When we look at the <em>Comparable</em> interface, we see that it just has one method, <em>CompareTo(Object o)</em> and that method just takes another object to compare our object to and returns 1 if ours is greater, 0 if it is the same, or –1 if ours is smaller.</p>
<p>Now let’s look at <em>sort(List list, Comparator c)</em>.&#160; In this case, we can see that the method to compare our two objects is passed in, but since we can’t pass methods in Java, Comparator is just an interface that we can implement that provides the comparison method.</p>
<p>If we look at the <em>Comparator</em> interface, we see it has one method we need to implement <em>compare(Object o1, Object o2)</em>.&#160; I’m sure you can guess what that method should return by now.</p>
<p>So regardless of the language, when you are looking at how to use a sorting algorithm, find the two things that it needs.&#160; The list is usually obvious, but the method to compare is almost always implemented in one of three ways.</p>
<ol>
<li>An interface the objects being compared implement.</li>
<li>A method that is passed in.</li>
<li>An object that is passed in that implements a comparison interface.</li>
</ol>
<h3></h3>
<h2></h2>
<h2>Step 3: Implement the method</h2>
<p>After you have figured out how to pass your list and your comparison method to the sorting algorithm, you need to actually write the comparison method.</p>
<p>If you learn to write a comparison method you can use it for any sorting algorithm, since all comparison methods do the exact same thing.</p>
<p>Fortunately, this is easy as well, because comparison methods always do the exact same thing.&#160; They take two objects and return whether the first one is larger, smaller, or equal to the second.&#160; That is it.</p>
<p>Don’t worry about sorting.&#160; Remember what I told you about the sorting algorithm black box?&#160; Let that sorting algorithm worry about sorting, all you have to do is decide whether 1 given item comes before a 2nd given item or if they are they same, nothing more.</p>
<p>Can you do that?</p>
<p>Sort people on age?&#160; </p>
<p>If person1.Age &gt; person2.Age return 1</p>
<p>Else if person1.Age &lt; person2.Age return –1</p>
<p>Else return 0</p>
<p>Psuedo-code, but pretty simple.</p>
<h2>Wrapping it up</h2>
<p>If you can figure out what method you can use to sort in your language, find how to pass in the list of things to sort and provide the comparison method, and implement the comparison method, then you can sort!</p>
<p><strong>Just remember to not get overwhelmed and think logically about the two things that all sorting methods need from you, and you’ll see how simple the whole sorting thing really is.&#160; </strong></p>
<p>You can be the guy that everyone asks about sorting instead of the guy copying and pasting some sorting code from the internet that you aren’t really sure how it works.</p>
<p>By the way, in C#, I would recommend just using the LINQ extension method OrderBy.</p>
<p>Very nice to do something like:</p>
<p>people.OrderBy(p =&gt; p.Age).OrderBy(p =&gt; p.Name);</p>
<h6><strong>As always, you can subscribe to this </strong><a href="http://feeds.feedburner.com/MakingTheComplexSimple"><strong>RSS feed</strong></a><strong> to follow my posts on Making the Complex Simple.&#160; Feel free to check out </strong><a href="http://elegantcode.com/"><strong>ElegantCode.com</strong></a><strong> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter </strong><a href="http://twitter.com/jsonmez"><strong>here</strong></a><strong>.</strong></h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1190&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2010/12/07/back-to-basics-sorting/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2010/12/harry-potter-sorting-hat_thumb.jpg" medium="image">
			<media:title type="html">harry-potter-sorting-hat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
