Expectations not working properly with subtests #1620
Unanswered
bartolek153
asked this question in
Q&A
Replies: 1 comment
-
No compilable example so this is mostly commentry. The first subtest looks wrong, you have: userRepo.On("GetUserById", mock.Anything, mock.Anything).Return(validUser, nil) but The second subtest is definately wrong, you can't assign untyped userRepo.On("GetUserById", mock.Anything, mock.Anything).Return((*User)(nil), errdefs.ErrDatabaseFailed) I think this is might be the error you are referring to. Your question lacks the actual error. Finally, it's not good to share the same mock in multiple subtests. It's better to make a new mock in each subtest. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I'm trying to create some unit tests combining
assert
andmock
packages, but I'm encountering an error that I suspect it may be due to a incorrect setup in the sample test code below:And this is what
MockUsersRepository
look like:The first subtest passes normally, second and third fail however. They tell me
err
variable is nil and is expected to returnErrDatabaseFailed
.Am I missing some setup in the MockUsersRepository type or in the test code since I'm using a unique mock instance to all subtests?
Beta Was this translation helpful? Give feedback.
All reactions