Fireship · @fireship

Test-Driven Development // Fun TDD Introduction with JavaScript

Uploaded June 4, 2021 · Length 12:55

Test-Driven Development // Fun TDD Introduction with JavaScript

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.

  1. 0:00

    red green refactor imagine you're

  2. 0:02

    sitting in a technical interview for an

  3. 0:04

    entry-level web developer job

  4. 0:05

    and they ask you to implement a dynamic

  5. 0:07

    time warping algorithm to measure the

  6. 0:09

    similarity between two sequences in

  7. 0:11

    logarithmic time

  8. 0:12

    instead of freaking out and wondering

  9. 0:13

    what this has to do with jquery you can

  10. 0:15

    just say no problem

  11. 0:16

    let me write a few test cases for that

  12. 0:17

    first not only will that buy you some

  13. 0:19

    time

  14. 0:19

    but it also makes you look like you know

  15. 0:20

    what you're doing test driven

  16. 0:22

    development is a technique where you

  17. 0:24

    describe the behavior of your code

  18. 0:25

    before you go and implement it if you

  19. 0:27

    trust the science

  20. 0:27

    testing will help reduce bugs and

  21. 0:29

    improve the maintainability of your code

  22. 0:31

    base in the long run and if you're new

  23. 0:32

    to programming

  24. 0:33

    knowing how to test your code is one of

  25. 0:35

    the most powerful ways to level up as a

  26. 0:37

    developer not only is it fun but it will

  27. 0:39

    also teach you about your code in

  28. 0:40

    unexpected ways and make you much better

  29. 0:42

    at debugging it today's video will teach

  30. 0:44

    you everything you need to know to get

  31. 0:46

    started with software testing as a

  32. 0:47

    developer

  33. 0:48

    we'll talk about a bunch of different

  34. 0:49

    testing strategies from a high level

  35. 0:51

    then take a hands-on approach by

  36. 0:52

    implementing unit tests from scratch

  37. 0:54

    with jest

  38. 0:55

    and we'll also look at end-to-end

  39. 0:56

    testing with a tool called cypress

  40. 0:58

    but most importantly by the end of the

  41. 1:00

    video you'll learn why testing is

  42. 1:01

    valuable and how to make the decision

  43. 1:03

    about whether or not you should test

  44. 1:05

    something because it's a practice that

  45. 1:06

    walks a very fine line between being

  46. 1:08

    valuable and a complete waste of time

  47. 1:10

    before we get started

  48. 1:11

    make sure to hit the like button and

  49. 1:12

    subscribe in the last video i explained

  50. 1:14

    how software testing works

  51. 1:16

    but if you missed it automated testing

  52. 1:18

    is basically just a way to write code

  53. 1:20

    that describes your requirements

  54. 1:22

    and validates your main application code

  55. 1:24

    now most developers i know and myself

  56. 1:26

    included

  57. 1:27

    generally don't start writing tests

  58. 1:28

    until we have a working feature

  59. 1:30

    or maybe we just don't write any tests

  60. 1:32

    at all and that's especially true with

  61. 1:33

    front-end development because ui

  62. 1:34

    requirements tend to change frequently

  63. 1:37

    but if you follow the principle of

  64. 1:38

    test-driven development you'll write

  65. 1:40

    your test

  66. 1:40

    before you implement your actual code

  67. 1:42

    and a common mantra

  68. 1:44

    is red green refactor which means you

  69. 1:46

    write a failing test first

  70. 1:48

    red then you write some code to get it

  71. 1:50

    passing green

  72. 1:51

    then you go back and optimize or

  73. 1:53

    refactor the code it's not always

  74. 1:55

    practical to do this

  75. 1:56

    but if you have a project with very

  76. 1:57

    clear requirements you might find that

  77. 1:59

    tdd