Testing

Last updated 7 months ago

This section is only relevant if you are using nodejs.

What You'll Need

Backbench account - Sign Up, the personal account will always remain free to use.

Prerequisites

  1. Sign In to Backbench account.

  2. Select +, in the upper right corner to create a Bench. For example, say testing and select CREATE or hit Enter.

Intro

Backbench can be utilized for testing your application, depends on your testing logic.

Here we'll provide you an example of functional testing.

Dependency required

In package.json, these libraries will be required.

package.json
{
"dependencies": {
"chai": "^4.1.2",
"chai-http": "^4.0.0"
}
}

Functional testing is a quality assurance (QA) process and a type of black-box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered (unlike white-box testing).[2] Functional testing usually describes what the system does. -Wiki

We'll walk through an example here, by creating a function and its test.

Paste following code in a module, then map it to endpoint.

asd.js
module.exports.endpoint = function(req, cb){
cb(undefined, {"msg": "Hello World"})
}

According to functional test we need to make sure output goes as

{"msg": "Hello World"}

Suppose the endpoint name goes as https://peeyushsrj-addressbookapp.beta-bench.backbench.io/hi.js.

Now create a module, to test the above:

"use strict";
var chai = require('chai');
var chaiHttp = require('chai-http');
var expect = require('chai').expect;
chai.use(chaiHttp);
function testing(cb){
chai.request("https://peeyushsrj-addressbookapp.beta-bench.backbench.io")
.get('/hi.js')
.end(function(err, res) {
try{
expect(err).to.be.null;
expect(res).to.have.status(200);
console.log(res.body)
expect(res.body).to.deep.equal({"msg": "Hello World"});
console.log("SUCCESS: " +new Date())
cb(undefined, {"status": "success"})
} catch(e){
console.log("FAILED: "+e)
cb(undefined, {"status": "failure"})
}
});
}
module.exports.endpoint = function(req, cb){
testing(cb)
}

After saving this on your module, you need to map it to endpoint. Now from the endpoint you can see the status.