unit testing and continuous integration

6
Slide 02: Stuff that everyone seems to put on their presentations... Senior Analyst Programmer, CogState ColdFusion since 2000 (v4.0) Patch Manager: Apache™ Subversion® Melbourne CFUG regular member / occassional presenter Stuff you might not know 10 Years In the Royal Australian Navy Father of four Motorcycle Fanatic: Honda CBR / Honda VFR Tropical Aquarium Enthusiast Gratuitous Self Promotion. All-round Top-Bloke Slide 03: Stuff We're Going to Cover Unit Testing MX Unit Another Neat Tool - ANT Integrating ANT with MX Unit Jenkins (Hudson) Continuous Integration Using it all together 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. 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!

Upload: gavinbaumanis

Post on 14-Jul-2015

445 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Unit Testing and Continuous Integration

Slide 02:

Stuff that everyone seems to put on their presentations...

• Senior Analyst Programmer, CogState

• ColdFusion since 2000 (v4.0)

• Patch Manager: Apache™ Subversion®

• Melbourne CFUG regular member / occassional presenter

Stuff you might not know

• 10 Years In the Royal Australian Navy

• Father of four

• Motorcycle Fanatic: Honda CBR / Honda VFR

• Tropical Aquarium Enthusiast

Gratuitous Self Promotion.

• All-round Top-Bloke

Slide 03:

Stuff We're Going to Cover

•Unit Testing

• MX Unit

• Another Neat Tool - ANT

• Integrating ANT with MX Unit

• Jenkins (Hudson) Continuous Integration

• Using it all together

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.

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!

Page 2: Unit Testing and Continuous Integration

Slide 04:

TDD :

Kent Beck; The creator of the Extreme Programming and Test Driven Development software development methodologies

Said;"Test driven development is a way of managing fear during programming."

He goes on to say that;

• Fear makes you tentative,

• Fear makes you want to communicate less,

• Fear makes you shy away from feedback.

Slide 05:

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.

• 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?”

• 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.

• In fact, the tests you write act as a sort of pseudo-documentation for the real code.

• They are (indeed) a technical specification for the problem your attempting to solve.

• 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.

Page 3: Unit Testing and Continuous Integration

Slide 06:

TDD – The Process

SO – what is the TDD Process then?

•Write a test

•Run the test

• Watch it Fail - see Red.

• Of course it is going to fail, there is no code yet - how can it possibly pass?

• So then : You Write your Code

• The Simplest code possible

• Don't over engineer it, don;t over invest.

• 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;

• Over engineering or complex solutions.

• The simplest cleanest code possible for the simple task of get the test to pass.

• Lastly, Watch the test pass

The result of you following this methodology is;

•The code is simple and clean

•It's small - it is for a discreet task

•It enables you to to speak about specific issues and simple solutions.

Slide 07 :

What is a unit then?

Something small, discreet that can be easily debugged.

Some examples might be;

• A Method / a Function

• A Single Source File

• If your working procedurally in .CFM templates

• A Custom Tag

• A UDF - User Defined Function

Page 4: Unit Testing and Continuous Integration

Slide 08:

Lets's take a look at a test and what it might look like.

We have a function. Lets get testing.

• write a test

• run the test.

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.

Just to prove that it isn't an elaborate stunt;Lets change the values and watch it fail.

There is an entire vocabulary on what you can assert.You can assert that;

•A result is true.

•A result is false

•A result is equal

•You can assert that “things” exist.

◦Variables / objects etc.

MXUnit

Slide 09 :

Ant – which stands for “Another Neat Tool”was 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.

• Portable - Same build file works for Windows / *nix / Mac OS

• You only need to learn one thing for all environments

• Easy to lean and use.

• Plenty of plug-ins for things like;

• Interacting with databases.

• Creating tables / adding columns etc.

• FTP / local file copy

• Version control polling / pushing

*** Show BUILD File.

Page 5: Unit Testing and Continuous Integration

Slide 10 :

I can almost hear the groans now....“Not another thing to learn....”“Who the heck uses XML anymore?”

The news isn't all bad – ANT is relatively easy to learn

Cheat Sheet :

• property - cfparam

• taskdef - cfimport

• copy - cffile

• delete - cffile

• ... - cffile

• zip - cfzip

So the learning curve... especially for smart, technical people is pretty much flat.

Slide 11 :

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;"Test driven development is a way of managing fear during programming."

• Being a script, it is repeatable.

• It can be scheduled

• Removes Human error from the process - when scripted correctly.

• Scriptable / repeatable / consistent

• Repeatable actions with consistent results - Removes fear.

• Removing fear;

• Increases communication

• Creates an academic environment

• Increases the knowledge of all team members

• Increases confidence in the work you do.

Page 6: Unit Testing and Continuous Integration

Slide 12:

Jenkins / Hudson Continuous Integration

• Monitors executions of repeated jobs, such as building a software project or jobs run by cron

• It is a Scheduler of ANT tasks.

• It enables you to more easily Monitor changes in the success / failures of builds.

• It provides Visual Results

• It can Email Results(and by default, does)

• Last time run / last successful build etc.

• ANT provides scriptable / repeatable processes for testing.

• And testing;Increases the confidence with which you code.

Slide 13:

•Let's take a look at it in action....