Created
April 20, 2023 22:10
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**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; | |
}); | |
}); | |
` |
Author
Nalini1998
commented
Apr 20, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment