Code Monkey home page Code Monkey logo

fec-tdd-workshop's Introduction

Front End Chapter | Test Driven Development Workshop

Front End Chapter Workshop to learn the ins-and-outs of test driven development

Ground Rules

Put your laptop on Do Not Disturb (We don't want those Teams messages coming through).

What is Test Driven Development (TDD)?

Quoting Kent Beck, "Test-driven development is a way of managing fear during programming". But why would you fear your own programming? Why would you fear your own code? Maybe it's not the code... maybe it's you that you should be afraid of. In my experience with TDD, I've learned that I can't trust myself without having a test to prove I programmed something right. That may sound a little extreme but it's true.

All of us know that we need tests whether that's because

  • We know we should do it (but secretly find testing tedious)
  • Our team and leadership expects good code coverage
  • It's "apparently" a better way to program

That's how I felt and the morale on my team wasn't helping either. We had a saying, "Coding the logic takes an hour but testing afterwards takes three days". Ever felt like that?

Let's flip that on it's head so that you start with a test, code a little bit, and then make the test pass. This is called the Red, Green, Refactor method.

Red, Green, Refactor

It looks like this:

  1. Red: Write a failing test
  2. Green: Write the smallest amount of code to make it pass
  3. Refactor: Remove any duplication

Why?

There's tons of benefits to TDD and I can testify to them. Here's a few:

  1. You're going to increase your code coverage by default
  2. You're going to write classes that are more decoupled, code that's easier to test, and cleaner code because you're constantly refactoring
  3. Refactor without the ๐Ÿ’ฆ
  4. Ship less ๐Ÿชฒ
  5. My personal favorite: Wishful coding

But you may think this sounds just like writing tests in general. TDD is not just unit testing. There's a difference: TDD is writing tests before you write the code.

TDD's strength lie in the unit test portion of the testing pyramid

Testing Pyramid

You want to write tests that run quickly so you shorten your feedback loop. You can hold off on the integration and E2E testing until later.

Enough talk. The best way to learn is through practice.

What are we going to code?

Creating Dollars, Peso, and abstracting them.

Getting Started

Go to your development folder and clone the repo

git clone https://github.com/patrady/fec-tdd-workshop.git

Open up the repo in your favorite IDE or if you're using VSCode then

code fec-tdd-workshop

Get everything setup on your machine and notice that there is a failing test

yarn install
yarn test

fec-tdd-workshop's People

Contributors

patrady avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.