2 Comments

Maurício, I always prefer to insert the data that I’ll be using in tests directly into the database, if it’s possible. I like this method because there’s no layer being able to cause a failing test.

I use data builders just when this isn’t possible, because, for example, if I need to do a search or an update test, I need to use a layer that’s able to insert that data. But, if we have a bug or a issue in the “post” method, the test using the “get” or the “patch”/“put” will fail, incorrectly, because the problem isn’t at those methods, but when I’m inserting using the “posts” method.

Can I get some hints about this?

Expand full comment
author

Hi, Delon! In this post, I assumed you have access to the database directly from your tests. If you don't, say, you are doing a more e2e test, having SQL files injecting data in the DB is one approach. Other would be to provide web services that would let you add the data you want to these services. Both have their pros and cons as you mentioned in your question. In the end, it's about picking what hurts you and your team the least :)

Expand full comment