Showing posts with label BDD. Show all posts
Showing posts with label BDD. Show all posts

Wednesday, 19 June 2013

Skimmer's Guide - Behaviour Driven Development with JavaScript




“BDD has many different aspects. Which of them are important depends on your perspective.”

WHAT IS THE ABOUT? 

Marco Emrich brings us a mature and enlightening insight into Behaviour Driven Development with JavaScript. Absolutely rammed full of excellent information, the book is nevertheless extremely well paced and reads very easily.

Beginning in earnest with a quick refresher on JavaScript, we are soon introduced to Jasmine, our JavaScript BDD weapon of choice ;) The underlying mechanics of BDD are explored (i.e. Red-Green-Refactor) before we are shown novel ways of generating data for our tests.

Particular attention is then spent on advising us how to organise/write our tests to maximise readability/maintainability. Following this we dive into Outside-In Development and how we can use it to flush out uncertainty. Use cases of the various types of 'test doubles' are covered, extensively so for mocks.

We finish by addressing the difficult question of "what is BDD?", bringing together everything we learnt into a formal methodology. The most important aspects are brought into focus and pointed in the direction of possible next steps into the BDD world.

WHAT STOOD OUT? 

JavaScript refresher (p. 7) 
Covering modern and functional aspects of JavaScript, this introductory chapter is incredible helpful for anyone rusty with JavaScript. Anyone experienced in JavaScript should probably simply skim/skip this though. 

Specs should be readable (p. 27) 
Great coverage of the DAMP/DRY principles here and throughout the chapter. Sound advice with warnings every developer should heed! 

Organising by feature or by fixture (p. 35) 
Interesting techniques for keeping tests cohesive and making them read naturally, through intelligent organisation and custom code tools. 

Using test doubles (p. 53) & Advantages and disadvantages of mocks (p. 61) 
Fantastic coverage on how and when to use dummy, stub and mock objects, including views on the pros and cons of mocking. 

Vocabulary (p. 61) 
A resonating account of the pitfalls of TDD for beginners and how an improved vocabulary better enables proper testing. 

IF YOU READ NOTHING ELSE... 

Baby Steps (p. 23) 
Wonderful teaching on the importance of having a "tight feedback loop". Emphasis it placed on how the longer it takes to find a problem, the harder it is to solve it. Taking baby steps when changing code will let you go faster! 

Triangulation (p. 42) 
A wonderful technique for "faking it until you make it", forcing you to test all the relevant paths through your code. 

Gerkin language (p. 66) & Goals and benefits (p. 67) 
Covers the fabled "Given Then When" syntax of BDD and how it isn't necessarily central to BDD.


CONCLUSION 

At less than £2.60 ($3.99) this book is insanely good value and I would highly recommend it to anyone starting to learn BDD, even if they have limited JS experience. Despite centring around JavaScript, the core concepts of BDD are covered magnificently and can be applied to any language. 

Highly accessible and easy to reference, this book definitely warrants inclusion on any developer's digital bookshelf.

Saturday, 6 April 2013

Behaviour Driven Development/Design

In my recent post about Trisha's design talk (http://arkangelofkaos.blogspot.co.uk/2013/03/ljc-event-trisha-gees-design-talk.html) I decided one of my goals was to sit down and properly learn what Behaviour Driven Development/Design was all about. Here are my thoughts...

Googling the subject immediately turns up the definitive article on the subject by Dan North: http://dannorth.net/introducing-bdd/ If you haven't read it yet, I highly recommend it as it is succinct and very easy to follow.

The basic idea of BDD is to align your code more to actual discrete pieces of business requirements (behaviour). This means that when you do TDD, your test must target missing behaviour in your system. Furthermore the tests, along with your classes and methods, should clearly describe their intent.

I've alway been a firm believer in writing "Plain English" code. With code completion in all modern IDEs, there is no excuse for obscuring your code with acronyms or unhelpful names. Making code read like normal sentences enables better communication between everyone.

I really like the tenents of BDD as it ideally keeps code cleaner. If you are having to use a really long sentence to explain what your code is doing, that is usually a warning sign to stop and think! However I am not enamoured with the idea of completely basing your development around BDD (using a tool like JBehave for instance). It seems a bit too prescriptive, although I admit I have not tried it in anger.

Overall, this has inspired me to think long and hard about my development process. Now really want to drill down and makes sure I am getting all the basics right!