Open ahmetremziata opened 3 years ago
If there are two tests and tests are calling same mock, second test mock data come with first test data.
I show example like this.
func TestMethodA (*testing.T) { //Given var data1 := "data1" mockCacheService.On("GetData").Return(data1) //When resp, err := service.GetData(req) //Then assert.Nil(t, err) assertion.NotNil(t, resp) } func TestMethodB (*testing.T) { //Given var data2 := "data2" mockCacheService.On("GetData").Return(data2) //When resp, err := service.GetData(req) //Then assert.Nil(t, err) assertion.NotNil(t, resp) }
You see that there are two tests. In second test "GetData" method come with first test data (data1). Note: If we run tests seperetaly there ara no error, but if we run tests together problem has occured.
Please make a reproducible example running on go.dev/play. Here is a template: https://go.dev/play/p/AsRNcxCRdWx
If there are two tests and tests are calling same mock, second test mock data come with first test data.
I show example like this.
You see that there are two tests. In second test "GetData" method come with first test data (data1). Note: If we run tests seperetaly there ara no error, but if we run tests together problem has occured.