Skip to content

cjohansen.no

Test Driven JavaScript - The Book

Test Driven JavaScript Development Rough Cuts

For those of you who didn't already know: I'm writing a book. It's about JavaScript, it's about unit testing and it's about Test Driven Development. It won't be out until October this year, but drafts are already available through Safari Rough Cut.

I've been tweeting tirelessly about writing this thing for quite some time, but as the Safari Rough Cuts program opened today I felt it suitable to give some more tangible information about it.

What's it about?

The book - tentatively entitled "Test Driven JavaScript Development" - is basically about test driven development and JavaScript. It's a subject that has interested me for some time. Test driven development (or behavior driven, if that's your cup) has made my life as a programmer so much easier - no longer do I need to worry about getting all the details right a one time, no longer do I need to plan out an entire interface prior to implementing it in order to produce a reasonable elegant result.

The book teaches unit testing and test driven development in the setting of JavaScript. But there's more - it also teaches JavaScript in the setting of test driven development. The intended audience is both JavaScripters looking for more sustainable development methodologies as well as programmers used to testing but unfamiliar with JavaScript.

What's inside?

The book has four parts, and anyone of them can be read in isolation, depending on prior experience.

Automated testing

The first part deals with automated testing, introduces asserts, unit tests and the test driven development methodology. It's slightly theoretical, but uses loads of examples and provides a good background for the later parts.

JavaScript for programmers

The second part is entitled "JavaScript for programmers", and hopefully, is just that. It gives a tour of the features that sets JavaScript apart from other languages. It's no beginners introduction to JavaScript, but instead assumes the reader knows how to program and deals with some of the finer details of the JavaScript language, such as its functions, prototypal inheritance and the object model in general. The second part also covers unobtrusive JavaScript and feature testing, important topics for applications aimed for the general web.

Real world test driven JavaScript

The third part of the book is the biggest one, and shows five "real world" examples of test driving JavaScript development. I've tried to make the examples as relevant and non-fictional as possible. These chapters work through five small projects in great detail. Test by test, line by line of production code, simple interfaces are built, refactored and explained. The quotes imply that there simply isn't room in a book to cover too big projects in such detail, and in order to get a wide range of topics, I've had to simplify some of these from what they would have looked like in "the real world".

The topic of these examples ranges from the observer pattern, an "Ajax" implementation, Comet, node.js and finally DOM scripting. They focus mainly on the testing and the process of using tests to design interfaces, refactor heavily and other concepts such as stubbing and mocking.

Testing patterns and best practices

The final part of the book sums up some lessons learned through the above examples from part 3 and dives deeper into some concepts such as stubbing and mocking, which are important topics to cover in order to write truly isolated unit tests.

On writing a book

The book is being published through Addison-Wesley Professional, and as such I am surrounded by a very smooth and professional machinery. I have to say, the writing process has been very pleasant, and I have a very nice editor and staff working on the book. AW provides a team of reviewers, and boy are these guys (and gal) great. They help out by finding everything from typos and questionable formulations to bad ideas that are hard to discover when you've got your nose deep into the material. I'm very lucky to have been able to do this.

Safari Rough Cuts

As I mentioned in the introduction, what prompted this announcement was the availability of the Safari Rough Cuts program for the book. Safari Rough Cuts is like "beta" for books. The three first chapters have just been made available in very early draft form, and anyone with a Safari account can read them and provide feedback right this instance. If you are on Safari I hope you want to stop by, read the chapters and provide some feedback. It will surely help the book get better!

As for those of you without an account, you can either get one, or wait. In any case, chapter 3 is freely available to anyone. It's the tools chapter, which covers quite a few tools, but focuses mainly on JsTestDriver which was chosen as the main tool for many of the examples.

If you're on Twitter, you'll find me as @cjno, do stop by!

Side note: This post was written to the sound of Snakes for the Divine, High on Fire's new album. It ain't Blessed Black Wings, and it ain't Death is this Communion, but it sure is a cool album. Check it out!

Hope as many as possible of you check it out and if you do, please tell me what you think!

Possibly related