Skip to content

Instantly share code, notes, and snippets.

@Nalini1998
Created April 20, 2023 22:10
Show Gist options
  • Save Nalini1998/17d21b07c481f969c3493dd9b441cfaf to your computer and use it in GitHub Desktop.
Save Nalini1998/17d21b07c481f969c3493dd9b441cfaf to your computer and use it in GitHub Desktop.
AUTOMATE AND ORGANIZE TESTS Setup, Exercise, and Verify In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive. The phases are defined as follows: Setup - create objects, variables, and set conditions th…
**Setup, Exercise, and Verify**
- In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive.
- The phases are defined as follows:
+ Setup - create objects, variables, and set conditions that your test depends on;
+ Exercise - execute the functionality you are testing;
+ Verify - check your expectations against the result of the exercise phase. You can use the assert library here.
- Clear separation of each phase makes a test easier to read, change, and validate.
---
`
const assert = require('assert');
// Naive approach
describe('.pop', () => {
it('returns the last element in the array [naive]', () => {
assert.ok(['padawan', 'knight'].pop() === 'knight');
});
});
// 3 phase approach
describe('.pop', () => {
it('returns the last element in the array [3phase]', () => {
// Setup
const knightString = 'knight';
const jediPath = ['padawan', knightString];
// Exercise
const popped = jediPath.pop();
// Verify
assert.ok.popped === knightString;
});
});
`
@Nalini1998
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment