Unit Testing and Continuous Integration

  • Published on

  • View

  • Download

Embed Size (px)


<p>Slide 02:</p> <p>Stuff that everyone seems to put on their presentations... Senior Analyst Programmer, CogState </p> <p>ColdFusion since 2000 (v4.0) </p> <p>Patch Manager: Apache Subversion </p> <p>Melbourne CFUG regular member / occassional presenter </p> <p>Stuff you might not know10 Years In the Royal Australian Navy </p> <p>Father of four </p> <p>Motorcycle Fanatic: Honda CBR / Honda VFR </p> <p>Tropical Aquarium Enthusiast </p> <p>Gratuitous Self Promotion.All-round Top-Bloke </p> <p>Slide 03:</p> <p>Stuff We're Going to CoverUnit Testing </p> <p>MX Unit </p> <p>Another Neat Tool - ANT </p> <p>Integrating ANT with MX Unit </p> <p>Jenkins (Hudson) Continuous Integration </p> <p>Using it all together </p> <p>Despite that impressive list, this isn't specifically about any one of these items.It is about a process / system that has the genuine ability to transform not only the way you code, but also the applications you architect and specifically the code you write.</p> <p>I believe that the process is of high value and that when attacked with dedication can bring about remarkable, positive changes in morale even if your a lone crusader, telecommuting in your Pyjamas most of the time! </p> <p>Slide 04:</p> <p>TDD :</p> <p>Kent Beck; The creator of the Extreme Programming and Test Driven Development software development methodologiesSaid;<br />"Test driven development is a way of managing fear during programming."<br /><br /><br />He goes on to say that;Fear makes you tentative, </p> <p>Fear makes you want to communicate less, </p> <p>Fear makes you shy away from feedback. </p> <p>Slide 05:</p> <p>Test Driven Development (TDD) allows us take steps towards controlling of all of these things. Set small / discreet attainable goals that you can attack vigorously.You don't need to struggle with the weight / the enormity of an entire application.</p> <p>Because the task is simple, singular there is no barrier to communication.Imagine you spend three hours working on an overarching / all encompassing design for a new application or feature.How likely are you to share that design with others when there is every possibility that they'll find something wrong with it and leave you with the feeling of; why did I even bother?</p> <p>Because the task is small - your investment upfront is quite small. And Subsequently, you have no attachment to any one idea you might have about it.</p> <p>In fact, the tests you write act as a sort of pseudo-documentation for the real code.</p> <p>They are (indeed) a technical specification for the problem your attempting to solve.</p> <p>And because Human's are visual creatures : You get the bonus of being able to actually see when you're work is able to cut the mustard - and when it hasn't quite made the grade.</p> <p>Slide 06:</p> <p>TDD The Process</p> <p>SO what is the TDD Process then?Write a test </p> <p>Run the test </p> <p>Watch it Fail - see Red.Of course it is going to fail, there is no code yet - how can it possibly pass?</p> <p>So then : You Write your Code The Simplest code possible </p> <p>Don't over engineer it, don;t over invest.</p> <p>You're aim is to get the test to pass to see it turn green in the shortest amount of time possible.That doesn't lend itself to;</p> <p>Over engineering or complex solutions.</p> <p>The simplest cleanest code possible for the simple task of get the test to pass. </p> <p>Lastly, Watch the test pass </p> <p>The result of you following this methodology is;The code is simple and clean</p> <p>It's small - it is for a discreet task</p> <p>It enables you to to speak about specific issues and simple solutions.</p> <p>Slide 07 :</p> <p>What is a unit then?</p> <p>Something small, discreet that can be easily debugged.Some examples might be;A Method / a Function </p> <p>A Single Source FileIf your working procedurally in .CFM templates</p> <p>A Custom Tag </p> <p>A UDF - User Defined Function </p> <p>Slide 08:</p> <p>Lets's take a look at a test and what it might look like.</p> <p>We have a function. Lets get testing. write a test </p> <p>run the test. </p> <p>I am using the MX Unit framework.You can view the results via the browser;there is also;an eclipse Plugin, so you can run your tests directly within your normal work application.</p> <p>Just to prove that it isn't an elaborate stunt;Lets change the values and watch it fail.</p> <p>There is an entire vocabulary on what you can assert.You can assert that;A result is true.</p> <p>A result is false</p> <p>A result is equal</p> <p>You can assert that things exist.Variables / objects etc.</p> <p>MXUnit</p> <p>Slide 09 :</p> <p>Ant which stands for Another Neat Toolwas originally created with the tagline of being a replacement for MAKE without all of Makes quirks.So what has that got to do with ColdFusion? After all we donlt need to configure / compile libraries in CFML...Well what we can do with Ant is;We can use it as an XML powered batch file / shell script processor. Because it is XML it is self-describing, human readable.</p> <p>Portable - Same build file works for Windows / *nix / Mac OS </p> <p>You only need to learn one thing for all environments </p> <p>Easy to lean and use. </p> <p>Plenty of plug-ins for things like;Interacting with databases.Creating tables / adding columns etc.</p> <p>FTP / local file copy</p> <p>Version control polling / pushing</p> <p>*** Show BUILD File.</p> <p>Slide 10 :</p> <p>I can almost hear the groans now....Not another thing to learn....Who the heck uses XML anymore?</p> <p>The news isn't all bad ANT is relatively easy to learn<br /><br />Cheat Sheet : property - cfparam </p> <p>taskdef - cfimport </p> <p>copy - cffile </p> <p>delete - cffile </p> <p>... - cffile </p> <p>zip - cfzip </p> <p>So the learning curve... especially for smart, technical people is pretty much flat.</p> <p>Slide 11 :</p> <p>So what is ANT going to do for me, really?Let's keep in mind what we saw on one of the first few slides.Kent Beck Said;<br />"Test driven development is a way of managing fear during programming."</p> <p>Being a script, it is repeatable. </p> <p>It can be scheduled </p> <p>Removes Human error from the process - when scripted correctly. </p> <p>Scriptable / repeatable / consistent </p> <p>Repeatable actions with consistent results - Removes fear. </p> <p>Removing fear; Increases communication </p> <p>Creates an academic environment </p> <p>Increases the knowledge of all team members </p> <p>Increases confidence in the work you do. </p> <p>Slide 12:</p> <p>Jenkins / Hudson Continuous IntegrationMonitors executions of repeated jobs, such as building a software project or jobs run by cron </p> <p>It is a Scheduler of ANT tasks. </p> <p>It enables you to more easily Monitor changes in the success / failures of builds. </p> <p>It provides Visual Results </p> <p>It can Email Results(and by default, does) </p> <p>Last time run / last successful build etc. </p> <p>ANT provides scriptable / repeatable processes for testing.<br /></p> <p>And testing;<br />Increases the confidence with which you code. </p> <p>Slide 13:Let's take a look at it in action....</p>