<?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/"
	>

<channel>
	<title>ryan norris &#187; Services as Software</title>
	<atom:link href="http://www.ryannorris.com/category/services-as-software/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryannorris.com</link>
	<description>managing software teams and delivering great results</description>
	<lastBuildDate>Fri, 25 Jun 2010 13:44:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>An Omniscient Learning Approach to Mock-based TDD</title>
		<link>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/</link>
		<comments>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 03:29:31 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Building Better Software]]></category>
		<category><![CDATA[Enterprise Architecture]]></category>
		<category><![CDATA[Java Development]]></category>
		<category><![CDATA[Services as Software]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.ryannorris.com/?p=69</guid>
		<description><![CDATA[I recently posted about why I think mocks are simply the easiest way to get the most bang for your buck in automated software testing.  But integrating it as part of a process is hard, and teaching it is even harder.  Young developers seem to have a hard time grasping the idea of testing isolated [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted about why I think mocks are simply the easiest way to get the most bang for your buck in automated software testing.  But integrating it as part of a process is hard, and teaching it is even harder.  Young developers seem to have a hard time grasping the idea of testing isolated units of code.  I&#8217;ll confess &#8211; for a long time, much of my unit testing involved setting up the appropriate test environments &#8211; Spring containers for persistence units, test databases, you name it.  It&#8217;s expensive to test this way, and there are only so many situations when integration tests are valuable.  On lean, agile teams &#8211; code coverage isn&#8217;t held in as high regard as having working software.  On lean, agile teams &#8211; tests are a driver towards design, but they do need to be rooted in some level of initial thought on how a problem needs to be solved.</p>
<p><span id="more-69"></span></p>
<p>So understanding how a unit test is traceable back to a technical design on an agile team is really a key differentiation between an approach that more closely resembles cowboy coding and an approach which is relatively holistic.  No scrum master, project manager, or even architect would advocate full designs in an agile environment &#8211; instead we opt for lighter weight approaches to technical design that provide a blueprint to the code.  For many teams, this is a CRC card &#8211; a simply way of documenting the various dimensions of an object-oriented unit.</p>
<p>What is a CRC, and how does it relate back to tests?</p>
<p><strong>Class</strong></p>
<p>The core unit of code that we will refer to is the class, but this can be really any aggregation &#8211; a function library even.  This represents a loose collection of related functionality that leverages common resources, represents a concept of actions or identity, or extends existing functionality.</p>
<p><strong>Responsibilities</strong></p>
<p>The responsibilities of the class form it&#8217;s <em>raison d&#8217;etre. </em>Commonly, we can analogize responsibilities with methods, but they may be more coarse grained &#8211; and our refactoring may indeed refine the level of detail with which we understand the functional responsibilities of the class.</p>
<p><strong>Collaborators</strong></p>
<p>From an interestingness perspective, particularly in the context of unit testing and mocking (or stubbing), collaborators really take the cake.  When we talk about <em>dependency injection</em> as the core pattern of test-driven development with mocks, collaborators are indeed what we are injecting into our class to power it.</p>
<p>I always ask my green developers to think about these things before starting any sort of development.  Once their CRC is done and we agree on the approach, I ask them to build the programming interface, stub the implementation, and then start writing tests.  A common example I like to use when I get that befuddled look is the idea of a car.  A car has a lot of complex stuff going on that if I needed to test dependent functions of the car against, I wouldn&#8217;t want to have to concoct all of the function they provide.  For instance, the engine is a complex piece of machinery &#8211; but if I solely want to to test how my transmission reacts to engine behavior &#8211; it&#8217;s the transmission class I want to ultimately test, and it&#8217;s reactions to different engine behavior.</p>
<p>Let&#8217;s bring it up a level and talk about a Car as the core class.  We want our car to be able to do two things &#8211; to have two <em>responsibilities</em>: accelerate and stop.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Car <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> accelerate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> additionalVelocity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">void</span> setTireGrip<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> gripFactor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">int</span> stop<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> overDistance<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> CannotStopException<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Motorable <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> injectGasoline<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> mlOfFuel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Stoppable <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">int</span> applyBrakes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> PadException, RotorException, WetRoadException<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So we&#8217;ve defined 3 interfaces.  Let&#8217;s say that I&#8217;m really interested in a case where I test how the car reacts to different stopping conditions.  Now, I&#8217;m demonstrating this in Java, so I&#8217;ll use syntax similar to Mockito &#8211; but the rules are the same:  I&#8217;m interested in testing the requirements of the car <em>observing the expected behavior of the brakes in those conditions</em>.  When the grip is set low, we expect the braking system to respond negatively and lock up.</p>
<p>We&#8217;ll also assume for now that I&#8217;ve stubbed out a skeletal implementation of the Car interface (meaning that everything throws a NotImplementedException for the time being).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Test
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testWetRoadConditionsWithLowFriction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// arrange</span>
   Stoppable s <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Stoppable.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Motorable m <span style="color: #339933;">=</span> mock<span style="color: #009900;">&#40;</span>Motorable.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   Car c <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CarImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setStopAbility</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setMotor</span><span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   c.<span style="color: #006633;">setGripFactor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   when<span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">applyBrakes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">thenThrow</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> WetRoadException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// act and assert - no real assertion, we're expecting an exception</span>
      c.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Should have seen a CannotStopException - there's not a lot of grip for road when road conditions are wet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>CannotStopException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// do nothing, we're a success!</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see, we&#8217;re not actually testing the brakes &#8211; we&#8217;re testing that under the given conditions that when the Stoppable interface throws an exception that prevents our car from stopping successfully that we are throw our own CannotStopException in response.  The stoppable interface is a <em>collaborator</em>; we are not interested in this case in unit testing it, we are interested in asuming a known behavior from it, and testing how the stop() ability of the Car implementation reacts to the WetRoadException that we have stubbed.</p>
<p>The alternative in the past would have been to actually create the implementation of Stoppable.  But having to unit test both items makes it difficult to isolate implementation issues.</p>
<p>So ultimately young developers, your unit tests need to test a single responsibility and not the responsibility of your collaborators.  You may eventually test how the two implementations interact &#8211; that is an integration test.  Ultimately though, there is more value in testing each individual unit and ensuring that the code is built to the spec of your lightweight design.  Then you can isolate integration issues and write tests that specifically address finding integration problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2009/04/16/an-omniscient-learning-approach-to-mock-based-tdd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unification of Java Weeds in a Standards Garden</title>
		<link>http://www.ryannorris.com/2009/02/09/standardizing-organic-java-development/</link>
		<comments>http://www.ryannorris.com/2009/02/09/standardizing-organic-java-development/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 13:56:39 +0000</pubDate>
		<dc:creator>Ryan Norris</dc:creator>
				<category><![CDATA[Building Better Software]]></category>
		<category><![CDATA[Services as Software]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JAX-RS]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.ryannorris.com/?p=23</guid>
		<description><![CDATA[PHP Web Frameworks are certainly plentiful.  Sun has proven that even attempting to set community standards around the interfaces for frameworks of all types does little to stem the tide of homegrown solutions.  JSR-311 is yet another standard that will try to unify the community.]]></description>
			<content:encoded><![CDATA[<p>After my post the other day in relation to building proper web UI architecture in PHP, my brain reverted to thinking about the complexities of web application development in Java and how in spite of standards, the amount of organic homegrown stuff that&#8217;s out there has muddied the water to the extent that it&#8217;s difficult to separate the wheat from the chaffe.  Sun has tried it&#8217;s darndest to follow the elephant and clean up behind it, but there is an increasingly sordid history of great ideas (<a title="Hibernate" href="http://www.hibernate.org" target="_blank">Hibernate</a>, <a title="Spring Framework" href="http://www.springframework.org" target="_blank">Spring</a>) that gained enough community momentum where Sun felt that these innovative platforms and their imitators should be unified behind a single standard.  In fact, it&#8217;s increasingly difficult to find parts of Java that <strong>were</strong> invented by Sun.</p>
<p>I haven&#8217;t been architecting Java solutions for a living in nearly a year now, and last I checked the state of the world was more or less:</p>
<ul>
<li>EJB had assimilated Hibernate and other ORM solutions as something now called JPA, which was neccesary and useful to standardize;</li>
<li>EJB had also taken elements of Spring to invert the once ubiquitous <em>locator</em> pattern and adopt dependency injection as the standard for satisfying collaborator relationships.  Of course, the Sun solution aimed to solve specific problems in EJB, and had less interest in solving the more general need for standardization around DI-based application frameworks;</li>
<li>JSF was crashing and burning in the web tier, with Gavin King once again trying to pick up the pieces and simplifying the entire stack through Web Beans.</li>
</ul>
<p>So to distill it down &#8211; middleware in Java was actually a pleasurable place to work, and the web tier was still a torture chamber.</p>
<p><em>Note: I&#8217;m leaving Velocity, Struts, Spring, and Tapestry out of the mix here.  That&#8217;s not to say that there isn&#8217;t value in some of these frameworks.  Tapestry was architecturally sound but hinders rapid development.  Struts and Spring both require siginificant configuration, and Velocity is&#8230;like Smarty for PHP.  All of them did so many things differently that it would be difficult to standardize around any one of them.  Additionally, the only one that could arguably be standardized within the exiting JEE stack is Spring &#8211; which attempts to solve many of the problems of front and middle-tier integrations. </em></p>
<p>Per my post from the other day, I really feel that the age of the server-based Web UI framework is dead.  MVC will always be a necessity, but re-usable controls and architectures that try to solve all of the world&#8217;s problems with different delivery mechanisms be it HTML or JSON are at a dead end &#8211; it&#8217;s simply not scalable.  So my attention turned to an <a title="James Stracham on JAX-RS" href="http://macstrac.blogspot.com/2009/01/jax-rs-as-one-web-framework-to-rule.html" target="_blank">article by James Strachan about JSR-311</a> and how he feels it could be the standard to solve much of the worlds problems.  JSR-311 addresses the <a title="JAX-RS, Restful Services for Java" href="http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features" target="_blank">JAX-RS</a> standard for delivery of RESTful services.  This has long been needed from Sun given the narrow nature of the JAX-WS spec, but James has the right idea.</p>
<p><em>&#8230;Having had a horrid time using Tapestry and Hibernate together on some projects in the past, I&#8217;m kinda over the whole concept of server side UI web frameworks personally (I&#8217;m putting my flame-proof suite on now). I kinda think if you want to do complex rich web UIs, use wizards or complex flows, just use GWT or JavaScript on the client (or Flex/Flash for video or crazy highly graphical widgets) and keep the server side fairly simple and very RESTful&#8230;.</em></p>
<p>So, I&#8217;m not the only crazy one out there.  That&#8217;s comforting.  But is a standard that serves as the foundation for tools to deliver RESTful services the answer?  From an architecture perspective, I&#8217;ve always been of the mindset that RESTful services, particular with its HTTP metaphors is just a DAO pattern exposed as services.  This is a pretty fine grain for me, but as Seam in Java and LINQ in .Net are beginning to prove &#8211; the value of coarse grained business services as provided typically by Session Beans in EJB may be a bit overstated.  So, does it make sense to build web frameworks that are really geared towards SaaS, and allow frameworks like Spring or Velocity or, hell even simple XSLT &#8211; take the helm when more traditional request-response mechanisms are needed?</p>
<p>And even more so, a cursory review of the JAX-RS doesn&#8217;t really present any options for <em>consuming</em> the services produced by implementers.  That&#8217;s somewhat understandable given that the product is typically vanilla XML or JSON or Text or whatever.  When I wrote my own RESTful service implementation using Spring a few years back, I made sure that XSD was attached and available when the service was XML.  This made it easy to write JAXB clients if your consumer was another Java application.  Slowing down development by forcing homogeneous consumers to parse the response as DOM seems like a likely outcome of not having SOME way of addressing this issue.</p>
<p>Taken together, I&#8217;m on board with the idea that JSR-311 could be a good foundation for a web framework that treats the client as being smart, rather than the dumb terminal approach of the past.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryannorris.com/2009/02/09/standardizing-organic-java-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
