Tag Archives: Mocha
It’s very common to have to write applications or libraries with dependencies that are completely foreign to your code. Regardless of whether it’s a database server, a web-service, some CLI-tools or even timers, suddenly your tests spend several seconds waiting for responses and/or don’t have strictly defined behavior. It’d be great if we could define foreign behavior programatically. Instead of actually interacting with them, we could just test our interactions.
The solution for this problem exists and is very simple: using stubs. Knowing how to use them will make your tests easier to write, predictable and a whole lot faster.
This article is a continuation of our previous articles about Single Page Application with Angular.js, Node.js and MongoDB part 1 and part 2.
In general, we appreciate unit testing in application, because at the time of delivery, we have much confidence about our piece of software regarding non-breaking of the code-base in production. There are integration tests, regression tests in our application, but we do not include those part in current scope of article, rather we emphasis on unit testing from development perspective.
We tried to cover the tests of methods of server side here. We expect, reader is already have some knowledge about unit testing of components in any given application. A test driven environment always help us through development life cycle for better maintainability of code-base and less iteration on bug fixing.
Mocha is a testing library for Node.js, created to be a simple, extensible, and fast testing suite. It is used for unit and integration testing, and it’s a great candidate for BDD (Behavior Driven Development).
This article will walk you through its installation and configuration, and also it will demonstrate its usage by implementing a color converter that can translate from RGB (red, green, blue) to hexadecimal color representation. In addition, we will create a web server that exposes the above converter, and demonstrates how to test asynchronous code.
Modern application development now’a’days demands a rigorous continuous deliver mechanism. This is especially true when it comes to the cloud.
You want to be able to get through the Build -> Measure -> Learn cycle as fast as possible. With cloud services, you can quickly create mechanisms to build, test and deploy your development team’s code. You can even maintain development and production branches.
The lab below will take you through this process and can be done on any computer that can run NodeJS.