You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I call call method AssertExpectations without having call the method On it panics
panic: runtime error: invalid memory address or nil pointer dereference
I usually have a test structure like the one below: not always I will call mock.On to prepare the mock - depends on the case and the preconditions. But I always check if the expectations are correct.
On Release 1.7.3 the mutex field in the Mock struct became a pointer to a mutex. And some methods check if the mutex is nil and initialize, but it is not the case of AssertExpectations. In fact this release break all of my test suites.
I note that there is a Test method that can initialize it, but I never use it. And the documentation says the test field is optional. Call Test seems vague and redundant (what is test? it tests my mock? it set a field to be used?), since I still need to call AssertExpectations.
What is the solution? rewrite my test suites or may I submit a patch to initialize the mock? or perhaps I should create a constructor for my mocks that calls mock.Test and prepare it ?
funcTestXxx(t*testing.T) {
testcases:= []struct {
labelstringpreparefunc(*myMockObject)
...
}{ ... }
for_, tc:=rangetestcases {
tc:=tct.Run(tc.label, func(t*testing.T) {
m:=&myMockObject{}
deferm.AssertExpectations(t)
tc.prepare(m)
// rest of the test
}
}
}
The text was updated successfully, but these errors were encountered:
If I call call method
AssertExpectations
without having call the methodOn
it panicspanic: runtime error: invalid memory address or nil pointer dereference
I usually have a test structure like the one below: not always I will call
mock.On
to prepare the mock - depends on the case and the preconditions. But I always check if the expectations are correct.On Release 1.7.3 the mutex field in the Mock struct became a pointer to a mutex. And some methods check if the mutex is nil and initialize, but it is not the case of
AssertExpectations
. In fact this release break all of my test suites.I note that there is a
Test
method that can initialize it, but I never use it. And the documentation says the test field is optional. CallTest
seems vague and redundant (what is test? it tests my mock? it set a field to be used?), since I still need to callAssertExpectations
.What is the solution? rewrite my test suites or may I submit a patch to initialize the mock? or perhaps I should create a constructor for my mocks that calls mock.Test and prepare it ?
The text was updated successfully, but these errors were encountered: