Test-Driven Development Guided Lab: Implement a Stack Object

137 Launches
Solution Overview

Test-Driven Development (TDD) is a practice of software development where tests that describe the intended behavior are written in a failing state before the code is written to pass the test. The result of this practice is a suite of tests that completely address all of the features of the code and serve as documentation to describe the code's behavior for future users.

This lab will teach the process of TDD's "Red-Green-Refactor" process while guiding the user through the implementation of a stack object.


This lab requires some knowledge of JavaScript (specifically ECMA Script 6) syntax. It can be launched by anyone who is interested in the content of the lab, however it may take a few tries to get tests to pass if you are not familiar with the language. The lab does include code blocks that can be copy/pasted into the lab that should get you back on-track if things are not working as expected.

Goals & Objectives

This lab will walk you through the process of implementing a stack data object. Tests are provided that will drive out the following features:

  • Report if it is empty or not.
  • Report how many numbers are in the stack (its size).
  • Must hold up to 10 numbers.
  • Must allow numbers to be "pushed" onto the stack.
  • Must allow numbers to be "popped" off of the stack.
  • Must obey "First in last out" order (i.e. the last number that was pushed onto the stack is the first number that is popped off).

Hardware & Software

This lab employs a Windows 10 VM with Visual Studio Code and Node software provided for testing the code.