dimanche 14 juin 2020

Mock function with wrong behavior still pass

I am writing a test for a function that depends on other functions. I use Gomock library to mock those dependencies' behaviors, this is one of them:

&mock.UseCaseToDependOn{
    UpdateStatusFuncMock: func(ID data.ID) ([]*ObjectsToReturn, error) {
        return case.in.updateStatusFuncReturnsObjects, case.in.updateStatusFuncReturnsError
    },
},

However, on code review, I realized that the UpdateStatusFuncMock mocking function that uses state machine pattern is returning illogical data based on the input, however, the test still passed nicely.

This is really odd to me, cause I believe that the test should fail in this case.

Also on other side, if I provide the data that just follow the logic then:

  • First, I need to understand the internal behavior of the functions that my test depends on. Is it a good thing or bad thing?
  • Second, I think that doing this just create false positive, since the test still passes for mocking function with wrong behavior.

Is it good to create mocking functions with input and output must abide by existing logic?

Aucun commentaire:

Enregistrer un commentaire