Reputation: 569
I am writing test cases for a GoLang application and i am using sqlmock for mocking the SQL queries but i am getting following error while executing go test
Params: [ call to query , was not expected, next expectation is: ExpectedBegin => expecting database transaction Begin]
Any idea on this?
Upvotes: 1
Views: 5110
Reputation: 978
I had same issue, because I used NamedExec
(not NamedQuery
) to perform my update, but was mocking ExpectQuery
in test
So,
if you have expression (i.e. use UPDATE
or INSERT
), you should use ExpectExec
if you have query (i.e. use SELECT
), you should use ExpectQuery
It's obvious, but I stuck with it for couple of hours
Upvotes: 0
Reputation: 11
sqlmock expected a begin, but instead got something else. Show the function and test here for more info.
Upvotes: 1
Reputation: 891
The error message means some SQL query was called which was not mocked.
Upvotes: 0