Intro

What Is TDD

Philosophy about how to develop software

Start by figuring out what the software should do

Write a test that tests for that functionality

Then, write only the code that makes the test pass

Automated Tests

Automated tests are code you write to ensure your application functions correctly

Why

Keeps you from over-engineering

Keeps you from writing features and functionality that aren’t part of the requirements

Ensures that app is well tested and thus easy to refactor and improve

Sponsors

Sauce Labs

Sauce Labs provides the world’s largest cloud-based Selenium Grid for the continuous testing of web and mobile applications. Founded by Jason Huggins, the original creator of Selenium, Sauce Labs helps companies accelerate software development cycles, improve application quality, and deploy with confidence across hundreds of browser / OS platforms, including Windows, Linux, iOS, Android & Mac OS X.

The Tech Academy

The Tech Academy is a licensed career school that teaches students Computer Programming and Web Development. The Tech Academy offers 4 different bootcamp tracks that include: Frontend Web Development, Python, C# & .NET Framework, and the Software Development Bootcamp, which is a comprehensive bootcamp covering all other bootcamp tracks.

What sets The Tech Academy apart from other coding bootcamps is the comprehensive curriculum, open enrollment, flexible scheduling options, online or in-person training options, self-paced study and exceptional job placement training. At the end of our program, graduates are well-rounded, full-stack junior developers!

Tweet our sponsors to let them know that you appreciate them

@saucelabs

@thetechacad

What We’re Building

We’re writing a change making function for a vending machine. The vending machine will call our function with the total amount paid and the total charged. We’ll have to return an array of the coins to return.

We’re going to be using qunit as our unit testing framework.

The Tests

test('getChange(1,1) should equal [] - an empty array', (assert) => {
  const result = getChange(1, 1); //no change/coins just an empty array
  const expected = [];
  assert.deepEqual(result, expected);
});
 
test('getChange(15, 100) should return [25, 25, 25, 10]', (assert) => {
  const result = getChange(15, 100);
  const expected = [25, 25, 25, 10];
  assert.deepEqual(result, expected);
});
 
test('getChange(86, 100) should equal [10, 1, 1, 1, 1]', (assert) => {
  const result = getChange(86, 100);
  const expected = [10, 1, 1, 1, 1];
  assert.deepEqual(result, expected);
});

Progression

  1. Write first test and cheat it with this:

    const getChange = (total, amountPaid) => {
      const change = [];
      return change;
    };
  2. Try to cheat second test and show the regression with the first test. Now we have to write the function for real to make it pass both.

  3. Stop cheating when it’s less work to solve the problem. (That’s now.)

  4. Write a new test that should return one of each coin.

Resources

Let’s try TDD resources

Let-s-try-TDD-resources-6f258631ef074b919a90dc466251c688

http://bit.ly/fccseattletdd