lundi 11 décembre 2017

Should I write very simple and very complex database tests for my Yii2 app?

I am a moslty self-taught web-programmer. Currently I am trying to incorporate tests into my very primitive Yii2 app (yes, you guessed it, a link shortener). I got the hang of unit-testing (or at least hope so), but testing using a database still eludes me. What I got from reading official documentation:

  1. Database fixtures are hard to set up.
  2. One should look at cost versus benefit when deciding whether to write a test for something.
  3. 100% Test coverage is a myth and should not be pursued.

But real world cases still make me confused. So, according to these principles, I should not write tests for an unmodified, just gii-generated model that interacts with my user form, because the cost vs benefit does not add up. But what if I will modify the form and model later, these database tests will surely come in handy.

And on the other end of a spectrum, I have a friend who is a miles better web-programmer but he has only recently started to write tests. He has an extremely complex application, and he needs to do an integration test for one large piece of business logic. To do it he needs to create 15 database fixtures (for 15 different, multicolumn tables). And he is wondering too whether it is worth time and effort.

Can you make a suggestion on these two extreme examples?

Aucun commentaire:

Enregistrer un commentaire