简体   繁体   中英

Getting error in sqlmock for GoLang

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?

sqlmock expected a begin, but instead got something else. Show the function and test here for more info.

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 (ie use UPDATE or INSERT ), you should use ExpectExec
if you have query (ie use SELECT ), you should use ExpectQuery

It's obvious, but I stuck with it for couple of hours

错误消息意味着调用了一些未被模拟的 SQL 查询。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM