Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage Research JavaScript Testing Approaches

JavaScript Testing Approaches


InfoQ's research widget has been deprecated and is no longer available.

​​​It should not need discussing that testing, taken in the loosest sense of the word, is widely agreed to be a positive thing. While the debate over TDD continues, we can at least agree on the principles that testing bestows various benefits, including allowing us to better understand our code, and identifying bugs. 

However, what we're wondering is how you are testing JavaScript code -- if indeed you are even testing ​at all.

The options:

  • Unit Testing tools​ ​(eg. Karma)

Created by the AngularJS team and built with Node.js, Karma is designed for low level (unit) testing. Their github How It Works article says "Karma is essentially a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results for each test against each browser are examined and displayed via the command line to the developer such that they can see which browsers and tests passed or failed.

Other Unit Testing tools include Testswarm, Jasmine,and many others.

  • Test ​​automation frameworks​ ​(eg. Selenium)

Originally developed by Jason Huggins and later merged with Simon Stewart's Web Driver, Selenium is an open source automation framework that provides a record/playback tool for authoring tests without learning a test scripting language. Test automation frameworks work with testing tools to automate the performing of certain types of tests effectively. Once automated tests have been developed, they can be run quickly and repeatedly. 

Other Test Automation Frameworks include QUnit, Sahi and many more.

  • Functional testing​ ​(eg. Cucumber)

Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test.  Functional testing is based on testing the functional requirements of software, and ensuring that the program physically works the way it was intended.

Specifically, Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid. Other Functional Testing tools include Capybara, among others.

  • I don't test

In the comments, please add a bit more information about ​how you are testing, and if you are testing​. 

Does the size or nature of the company you work for have​ any impact on​ how you test? Perhaps you have found very different attitudes and approaches towards testing depending on the project or company. 

If you aren't testing, again let us know your experiences in the comments.