Javascript - Test Framework

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > Javascript - Test

1 - About

Test - Unit Test Framework (xUnit) in Javascript

A test framework is composed of two part that you can use separately:

Advertising

3 - Implementation Example

  • The function to test named plus1
function plus1(a){
    return a + 1;
}
  • The test function of the plus1 function
function test(then, expected) {
    results.total++;
    var result = plus1(then);
    if (result !== expected) {
        results.bad++;
        console.log("Expected " + expected + ", but was " + result);
    }
}
  • The run
var results = {
    total: 0,
    bad: 0
};
test(1, 2);
test(2, 4);
  • The result
console.log("Of " + results.total + " tests, " + results.bad + " failed, " +  (results.total - results.bad) + " passed.");

4 - Documentation / Reference

web/javascript/test/framework.txt · Last modified: 2019/02/16 17:40 by gerardnico