in General

μHarness: Lightweight (<600 byte) JS testing harness

I finished some homework early so I took ten minutes to spin out a piece of code I actually wrote as part of a class project (COEN164 shout out; thanks to Evan Paul for the praise that spurred me into repo-fying this) into a proper open source repo.

I’ve often been frustrated with super heavy and feature-rich testing harnesses that I have to spend 20 minutes looking at before I can even write a test. μHarness aims to solve that with an ulta-low-frills system that serially runs functions and compares their output to an expected value; nothing fancy in the slightest went into the making of this.

Simply put your functions in a JSON object with the test name as the key and and anonymous function that returns an array of [actual value, expected value] and μHarness will take care of the rest.

Be forkful and multiply; MIT licensed on Github.

var tests = {
    // test titles will have underscores conveted to spaces
    world_isnt_on_fire: function() {
        var actual = true;
        var expected = true;

        // return an array with the zeroth element as the expected output and the first as the returned/testing output
        return [expected, actual];
    },

    this_test_will_fail: function() {
        return [1 === 1, false];
    },
};

runTests(tests);

yields

Write a Comment

Comment