Unit testing - tooltwist/documentation GitHub Wiki
Unit and Performance testing with JUnit
--
Unit testing is where a specific piece of an application is being tested, independent of the rest of the application. The objective is to check that the various parts of an application work properly, before they are assembled and deployed.
In particular, unit tests should check errors and other conditions that may be difficult to replicate in the complete application. Forcing database errors, network errors, missing data, bad parameter combinations, etc, are relatively easy to do when creating unit tests, but very hard to replicate in a completed application.
Similarly, an application may contain multiple code paths, depending on various factors. Unit testing can check the various permutations work correctly, and exhaustively check hundreds or thousands of combinations of data. Such tests are unpractical to test by hand, or through a user interface.
Non-typesafe languages
Languages such as Javascript are not "type safe". For example, with Java the parameters passed to every method are checked at compile time (or even earlier if you're using an IDE like Eclipse), and this prevents calling functions and methods with incorrect parameters. In Javascript however, you can write code to pass anything to a method, and you won't know there's a problem until an error occurs at runtime.
To avoid these problems being discovered in production, it's important to uncover these errors through careful unit testing, because there's limited checking available from the compiler.
Unit testing Java code
Java code is best tested using jUnit, a java based testing tool that is automatically supported by both Eclipse and Maven. While unit tests normally simply result in a pass or final result, a simple modification allows jUnit tests to be run multiple times and timed.
Instructions for using jUnit can be found here.
Unit testing Node.js programs
There are many frameworks that can be used for testing Node.js code. For consistency of learning, we should stick with just one, and for this we have chosen Mocha.
Instructions for using Mocha [can be found here](Unit Testing using Mocha).
--