NodeJS Simple Logic Test

Simple Logic Test

I would like to write test code to verify logic code(not web related).
For example, parameter filters or calculation codes in server side logic.
Want to put them into get/post codes of NodeJS?


NodeJS has Simple Assert class for checking.
To use this,


Just add require(no need additional package)

Unfortunately, different from JUnit or other good test framework, it cannot detect success and fail.
When the test reached fail test in your code, happen exception(error) and program stops.

It’s just for checking.


I would like to test following code


var isBlank = function(str) {
    return str == null || str.length == 0;

module.exports = {
  isBlank : isBlank,

This is test codes

Test Codes(stringutiltest.js)

var assert = require('assert');
var stringutils = require('../utils/string/stringutil')  // relative path
console.log("Success Blank Check Test");

How to run(run nodejs code)

node stringutiltest.js

If the test succeeds, you can see “Success Blank Check Test” on your console.