Nomad Kim 2023. 4. 5. 06:29

What to & Not to Test

  • What should & shouldn’t be tested
  • Good tests are short & concise

key points

  • What should & shouldn’t be tested
    • Only test your code
    • don't test third-party code
    • don’t test what you cannot change

Example, fetch() API

  • Don't test if it works as intended
  • Don't test your server-side code implicitly via your client-side code
  • Write separate tests for your backend code instead

Do Test your client-side reaction to different response & errors.

 

Writing Good Tests

1. AAA - Arrange - Act - Assert

 

2. 1 - Only test one thing

  • For this, if function includes many code inside, separate it

3. focus - focus on the essence of a test when arranging

  • Do not overuse meaningless cases. e.g. below. two numbers are enough for testing.

4. < - keep your number of assertions(”expect”) low

  • avoid too many expects in a single it!

Only Test One Thing

What is one thing?

: means One feature! e.g. validate input OR transform it