dimanche 15 septembre 2019

How to write clean integration test in golang?

I want to write an integration test using Golang and MySQL. But I confused how to do this clean. I have 4 functions: create, get, update, and delete. Is it a good practice if I just have one test function to test all my code? For example:

func TestCRUD(t *testing.T){
    t.Run("success case", func(t *testing.T){
         // call create func

         // call update func

         // call get func

         // call delete func
    })
}

If I have code like above, I just have one test function to test all my code. If I want to add a test case, I just add to TestCRUD() function. Is it a good practice?

Or should I write test function for each CRUD function? So I have 4 test functions and every test function also have many test cases. How can I write my integration test clean?

Aucun commentaire:

Enregistrer un commentaire