Fireship · @fireship
Test-Driven Development // Fun TDD Introduction with JavaScript
Uploaded June 4, 2021 · Length 12:55
Summary
Learn Test-Driven Development (TDD) with JavaScript, including unit testing with Jest and end-to-end testing with Cypress.
- test-driven development
- javascript testing
- jest testing
- cypress testing
- unit testing
- end-to-end testing
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
red green refactor imagine you're
- 0:02
sitting in a technical interview for an
- 0:04
entry-level web developer job
- 0:05
and they ask you to implement a dynamic
- 0:07
time warping algorithm to measure the
- 0:09
similarity between two sequences in
- 0:11
logarithmic time
- 0:12
instead of freaking out and wondering
- 0:13
what this has to do with jquery you can
- 0:15
just say no problem
- 0:16
let me write a few test cases for that
- 0:17
first not only will that buy you some
- 0:19
time
- 0:19
but it also makes you look like you know
- 0:20
what you're doing test driven
- 0:22
development is a technique where you
- 0:24
describe the behavior of your code
- 0:25
before you go and implement it if you
- 0:27
trust the science
- 0:27
testing will help reduce bugs and
- 0:29
improve the maintainability of your code
- 0:31
base in the long run and if you're new
- 0:32
to programming
- 0:33
knowing how to test your code is one of
- 0:35
the most powerful ways to level up as a
- 0:37
developer not only is it fun but it will
- 0:39
also teach you about your code in
- 0:40
unexpected ways and make you much better
- 0:42
at debugging it today's video will teach
- 0:44
you everything you need to know to get
- 0:46
started with software testing as a
- 0:47
developer
- 0:48
we'll talk about a bunch of different
- 0:49
testing strategies from a high level
- 0:51
then take a hands-on approach by
- 0:52
implementing unit tests from scratch
- 0:54
with jest
- 0:55
and we'll also look at end-to-end
- 0:56
testing with a tool called cypress
- 0:58
but most importantly by the end of the
- 1:00
video you'll learn why testing is
- 1:01
valuable and how to make the decision
- 1:03
about whether or not you should test
- 1:05
something because it's a practice that
- 1:06
walks a very fine line between being
- 1:08
valuable and a complete waste of time
- 1:10
before we get started
- 1:11
make sure to hit the like button and
- 1:12
subscribe in the last video i explained
- 1:14
how software testing works
- 1:16
but if you missed it automated testing
- 1:18
is basically just a way to write code
- 1:20
that describes your requirements
- 1:22
and validates your main application code
- 1:24
now most developers i know and myself
- 1:26
included
- 1:27
generally don't start writing tests
- 1:28
until we have a working feature
- 1:30
or maybe we just don't write any tests
- 1:32
at all and that's especially true with
- 1:33
front-end development because ui
- 1:34
requirements tend to change frequently
- 1:37
but if you follow the principle of
- 1:38
test-driven development you'll write
- 1:40
your test
- 1:40
before you implement your actual code
- 1:42
and a common mantra
- 1:44
is red green refactor which means you
- 1:46
write a failing test first
- 1:48
red then you write some code to get it
- 1:50
passing green
- 1:51
then you go back and optimize or
- 1:53
refactor the code it's not always
- 1:55
practical to do this
- 1:56
but if you have a project with very
- 1:57
clear requirements you might find that
- 1:59
tdd


