Slide 1

Slide 1 text

The Art of Unit Testing Jessica Cecilia Budianto | Software Engineer - Web Platform

Slide 2

Slide 2 text

Agenda ● Definition ● Principles ● Structure ● Preferences ● Practice

Slide 3

Slide 3 text

Definition

Slide 4

Slide 4 text

The benefits ● Helps to detect potential bug in code ● Reflects current code quality ● Made sure the code still works properly after refactor / major changes ● Documents the features and user flows of our code ● Trains our mindset to be a better software developer ○ How user interacts with our code ○ How edge cases and error might arise from our logic ○ Improves attention to detail

Slide 5

Slide 5 text

Principles

Slide 6

Slide 6 text

Fast It shouldn’t take long 🤔

Slide 7

Slide 7 text

Isolated / Independent Not depending on other test cases

Slide 8

Slide 8 text

Repeatable Not relying on e.g: network connection

Slide 9

Slide 9 text

Self Validating A test should immediately acknowledges whether it succeeds

Slide 10

Slide 10 text

Timely A test should be able to be written before development even started

Slide 11

Slide 11 text

Understandable A test should be like telling a story

Slide 12

Slide 12 text

Stucture

Slide 13

Slide 13 text

General Test Structure

Slide 14

Slide 14 text

Preferences

Slide 15

Slide 15 text

Top down vs Bottom up

Slide 16

Slide 16 text

https://kentcdodds.com/blog/write-tests

Slide 17

Slide 17 text

Test Driven Development (TDD)

Slide 18

Slide 18 text

But the downsides… ● Too focused on testing and making it passed ● Time consuming ● Harder for big codebase ● Even harder if it’s legacy code ● Might write a wrong test or miss the edge cases instead

Slide 19

Slide 19 text

Behavior Driven Development (BDD)

Slide 20

Slide 20 text

Practice

Slide 21

Slide 21 text

Github: https://github.com/jessicacb12/ basic-calculator Vercel: https://basic-calculator-psi.vercel.app/

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Unit Testing will not just affect your code quality, but also your collaboration with stakeholders