- Get access to your production code & test libraries within your test code
- Use
describe
andit
blocks to create a test fixture - Write a basic test which enforces a happy-case scenario
- Run the test suite with a green result
- Write tests for other happy-case scenarios, and refactor the test code if necessary
- Write edge-cases for unexpected input
- Write a test and then production code to handle invalid inputs
- Refactor the production code using tests as a safety-net
- Commit any outstanding changes on your Prac01 branch:
git commit -am 'Some message'
- Head back over to master:
git checkout master
- Check out the Start Point for Prac 2:
git checkout Prac02-StartPoint
- This references a defined tag in the repository, you must use exactly this name
- Create a branch to make your changes on without impacting the main repo:
git checkout -b Prac02
- This branch is your own working space, you can call it anything you want
- Use node's
require
to get access to the NameToNumberService for your test code - Also get acces to Chai to perform assertions
- Add a top-level
describe
block to describe the thing we're testing - Add a second-level
describe
block to describe the scenario we're testing - Add an
it
block to create your first test case - Inside the
it
block, write code to set up test data and call the service - Add an assertion to actually verify the result
- Run the test and see a green result
Here's a step-by-step walkthrough of the practical steps, for if you get stuck :)
- Use node's
require
to get access to the NameToNumberService for your test codevar nameToNumberService = require('../src/name-to-number-service');
- Also get acces to Chai to perform assertions
var chai = require('chai');
- Add a top-level
describe
block to describe the thing we're testingdescribe('NameToNumber Service', function() { ... });
- Add a second-level
describe
block to describe the scenario we're testingdescribe('with 4 buckets', function() { ... });
- Add an
it
block to create your first test caseit('should put Alice in the first', function() { ... });
- Inside the
it
block, write code to set up test data and call the servicevar inputName = "Alice"; var buckets = 4; var expectedBucket = 1; var actualBucket = nameToNumberService.generateNumber(inputName, buckets);
- Add an assertion to actually verify the result
actualBucket.should.equal(expectedBucket);
- Run the test and see a green result
npm test