Testing Error Cases and Failing Early | Go Tests #2

Sdílet
Vložit
  • čas přidán 15. 12. 2019
  • What is failing early and why should you care? Sometimes it doesn't make sense to continue running a test if one of the first assertions already failed. For example if you want to test for the "name" field of a "Post" object, but already identified that your post is nil/null, you're in for trouble. This also becomes relevant when testing for error cases. In this second video of our Golang Testing Series, we're covering both how to test for errors as well as how to abort the execution of a test early if a condition is not met.
  • Věda a technologie

Komentáře • 5

  • @kubucation
    @kubucation  Před 4 lety +4

    At 1:40 I'm preparing to test for the message of the errors. It's debatable whether you actually need to do that in real life. Sometimes it makes sense to just check whether an error is nil/not nil. In this you wouldn't have to fail early at all as the test would already be complete. I sometimes test for error messages when the UX of the error message is very important. For example when testing user validation the error message obviously plays a role - if the user entered the wrong phone number, showing "invalid name" is not good enough for our test. Another way to test that is using typed errors, something that we will get into a bit later. For now, it was important for me to show that if you have to abort the execution of a test early, this is how you do it.

  • @s_shyamdwivedi5110
    @s_shyamdwivedi5110 Před 3 lety +7

    Please continue this testing series. It is very helpful and you are explaining it very well in very simpler manner.

  • @LEGnewTube
    @LEGnewTube Před 2 lety +1

    No third video :(

  • @anniestar8837
    @anniestar8837 Před 3 lety +1

    great and helpful video for testing.

  • @haroldarriola5625
    @haroldarriola5625 Před rokem +1

    😢