Review #2 about the JavaScript Unit Testing Book

Attached below the review of Juanjo Fern├índez about the “JavaScript Unit Testing” book:

JavaScript Unit Testing

JavaScript Unit Testing Book

Improving your JavaScript code
“I suppose at least in a generic way you know what is unit testing, but to sum it up in a few words, according to Wikipedia:

Unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use.

By starting an application development, when it has relatively few lines of code all “fits” perfectly, but later when you want to add, modify, or delete certain functionality, this can become a big problem since when changing anything probably you will be breaking a few by the way.

Thanks to unit testing you can modify any module in your code, launch the tests, check failures, correct, and ready. Everything will still work in a clean, quick, and tidy way.

Once completed this short introduction, I’m going to review a book I’ve been reading these days and is about this theme: JavaScript Unit Testing:

Chapter 1 – Unit Testing JavaScript Applications: You’ll find the only theoretical part of the entire book on the first pages of this chapter, where you’ll learn what are the unit tests, why they are needed, and different approaches to create the tests: traditional unit testing and TDD.

Once this part is completed, you’ll see how works the application on which you’re going to make all the tests you’ll find in the book. It’s an application with the backend programmed in Java and a good amount of JavaScript in the frontend, that it really is what you’ll be interested to make the tests. The application allows you to complete a new user registration, authenticate and check the weather in some cities.

Don’t be scared by the fact that the application’s backend is programmed in Java: you won’t see anything of Java throughout the entire book however if you want to run the application in your computer, you’ll need to install Apache Tomcat.

Chapter 2 – Jasmine: Jasmine is a behaviour-driven development framework for testing JavaScript code. The behaviour-driven development is based on TDD.

The Jasmine test cases give more importance to the application business value over the technical details. Also are written in natural language so they can be understood by people without technical background.

In this chapter you’ll learn to install, configure and write tests with Jasmine on the application JavaScript code you saw in the first chapter, including Ajax.

Finally you’ll use together jQuery and Jasmine thanks to an available plugin that allows an easy integration between these 2 frameworks.

Chapter 3 – YUI Test: In this chapter you’ll learn to use one of the most popular unit testing frameworks: YUI Test.

YUI Test is part of the open source library for JavaScript and CSS called YUI, but with YUI Test you can test any JavaScript code, even if you don’t use YUI.

As with the previous chapter with Jasmine, in this case you’ll make unit testing with YUI Test on simple JavaScript code for later create the necessary unit testing for the application included with the book.

In addition to this you’ll see how to automate your unit testing integrating YUI Test with Selenium Driver.

Chapter 4 – QUnit: The third unit testing framework that you’ll learn to use is QUnit. It’s the framework used by all the projects related to jQuery (jQuery, jQuery UI, and jQuery Mobile) but you can use it to test any JavaScript code.

QUnit is very popular and has a simple syntax that allows you to run the tests from a browser.

Like in previous chapters, you’ll see how to install and configure QUnit, run your firsts tests, and once you’ve got a solid basis create the necessary tests for the weather application.

Chapter 5 – JsTestDriver: JsTestDriver (JSTD) is one of the most powerful frameworks for unit testing because in addition to the framework, it incorporates a test runner that can run other unit testing frameworks. All contained in a JAR file that includes everything you need to start to create your tests.

This last chapter goes similar path than previous: you’ll learn to install and configure JsTestDriver, you’ll make basic unit testing to learn its functioning and at last you’ll create the tests for the application you already know, but also you’ll learn to generate complete reports with the testing data, and to integrate JSTD with other JavaScript frameworks like Jasmine or QUnit.

Finally you’ll see how to integrate JSTD with the Eclipse IDE thanks to the JSTD Eclipse plugin.

It’s a short book compared with other books published by PacktPub but the content quality hasn’t been reduced. In any case I’ve missed information about other frameworks based on node.js that are becoming very popular like Mocha or CasperJS.

Another thing that could have improved is the application included with the book code. Since it’s a book about JavaScript it should be an application developed with node.js and not with Java, further it would have been easier to run on your computer, since to run the included application you need to install Apache Tomcat.

Beyond these minor flaws that I mentioned, It’s a highly recommended book, which includes a wealth of information and code from the most popular unit testing frameworks in the JavaScript community.

When you have finished reading it you will have a strong foundation to begin creating unit tests for your applications, which will improve your code and will optimize the time that you spend to modify existing applications.”


The book on PacktPub:

One thought on “Review #2 about the JavaScript Unit Testing Book

  1. Great info. Lucky me I found your website by accident (stumbleupon).

    I have book marked it for later!

Comments are closed.