> For the complete documentation index, see [llms.txt](https://backbench.gitbook.io/backbench-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://backbench.gitbook.io/backbench-docs/testing.md).

# Testing

## 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.

{% code title="package.json" %}

```javascript
{
  "dependencies": {
    "chai": "^4.1.2",
    "chai-http": "^4.0.0"
  }
}
```

{% endcode %}

{% hint style="info" %}
**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*](https://en.wikipedia.org/wiki/Functional_testing)
{% endhint %}

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.&#x20;

{% code title="asd.js" %}

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

{% endcode %}

According to functional test we need to make sure output goes as&#x20;

```javascript
{"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:

```javascript
"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.*
