Automated Testing
A test driven development cycle simplifies the thought process of writing code, makes it easier, and quicker in the long run.
Ava
Before we start, let's open the ./src/index.js
file and write some code that can be tested.
exports.echo = function () {
return 'Hello World';
}
Install the required packages.
$ npm i --save-dev ava
Open the ./package.json
and add some configuration as shown below.
{
"ava": {
"files": [
"./tests/*.js",
"./tests/**/*.js"
],
"concurrency": 5,
"failFast": true
},
"scripts": {
"test": "ava"
}
}
Create a new file ./tests/index.js
and write a simple test.
const test = require('ava');
const {echo} = require('../src');
test('returns Hello World', async (t) => {
t.is(echo(), 'Hello World');
});
Execute the npm test
command to run the test.