Test Drive?

Joseph K Abe
2 min readJul 8, 2021

--

I am currently searching for jobs as a software developer and am seeing a lot of postings that are looking for a Dev with experience in test driven development (TDD). Sadly I was not that, but am working on rethinking the way that I code to be more test driven.

So before we get started what is Test Driven Development...? Basically it is as it sounds. Writing tests (Unit tests), writing code to pass the unit tests, then finally refactoring and optimizing the code. This style of developing software allows the developer to test for functionality right from the beginning, which means less nasty surprises when you think you are almost done with your project! To sum it up you keep testing your code until you pass all the tests you have written. Also it comes in handy when a communicating with clients (most of the tests are written in plain readable english).

I am focusing mostly on Javascript at the moment so here are some of the most used JS testing frameworks

  1. MochaJS
  2. JEST
  3. Jasmine
  4. Karma
  5. Puppeteer

All of the testing frameworks listed above are good options, but I chose to start with Mocha. Below are the instructions to get started from the official website https://mochajs.org

Install with npm globally:

$ npm install --global mocha

or as a development dependency for your project:

$ npm install --save-dev mocha

As of v9.0.0, Mocha requires Node.js v12.0.0 or newer.

GETTING STARTED

$ npm install mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor

In your editor:

var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});

Back in the terminal:

$ ./node_modules/mocha/bin/mocha  Array
#indexOf()
✓ should return -1 when the value is not present
1 passing (9ms)

Set up a test script in package.json:

"scripts": {
"test": "mocha"
}

Then run tests with:

$ npm test

I will end it at installation for now and deep dive into MochaJS in next week’s blog. Oh btw this will be a series of weekly blog posts documenting my journey job searching and the technologies I am learning. Stay tuned and wish me luck!!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response