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.
The error message means some SQL query was called which was not mocked.
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
Related
I'm having an issue in Symfony when it comes to test my API. I want to get a field and its values that I insert with an orderBy in my DQL. I'm using a getSingleResult to get the result.
When I get it in Postman, the orderBy is functionnal.
When I try to get it in my console running php bin/phpUnit, the orderBy is inefficient. If I replace getSingleResult by getArrayResult, it works but I don't have an object and that's not what I want.
Is there someone who know's about a problem like this one ?
I found the answer : when I'm testing my API I'm adding the entity, then I try to get it, but the collection in the parent entity is kept in cache. The fact is Doctrine needs to know that in this particular case the entity must be refreshed so I told my entity manager to use the HINT_REFRESH. Now it's working just fine.
I have a function inside another function that is supposedly getting called, according to my expect(Parse.User.Login).toHaveBeenCalled() line, but there are some console statements inside the callback to that which aren't showing up.
Is there some type of dependency I'm missing on my unit test causing the callback not to have called? I think it is getting to the server, because it tells me I need a Parse.initialize with the application keys if that's not present.
How do I resolve it?
It just occurred to me, maybe that's something in Parse.js telling me I need the Parse.initialize(keys,keys). I changed the parse keys to nonsense, and its not telling me they're wrong, so it must be that parse isn't being touched at all. No request is being sent to the server.
I've been putting up a few questions about this, but now I guess this can't be done with Karma-jasmine -- at least the way the app is set up right now. It's depending on a web service to give the errors, instead of having an angular directive set up up front to detect the errors in the fields beforehand.
I'm a newbie at this obviously, or I would have recognized this sooner:
This type of testing, where you are depending on responses from the server and that's that, should be delegated to E2E tests.
Meaning, here what am I supposed to test that wouldn't be just hardcoding the desired response right into the jasmine Spy? What would that do to just set the rootScope to a user attribute? Maybe, if state.go changed the view to another page, and then acted on the $rootScope data, this would make sense. But for now, there's no point. I'm not designing the next step, nor do I know what it is at the moment, so I can only sit back.
I am writing a provider hosted SharePoint 2013 application. I'm using SharePoint online.
Since the people picker isn't supported in this scenario, I need to build my own. I found the SearchPrincipals method. That seems like exactly what I'm looking for, but no matter what I try, the method is returning with 0 results.
What little information I've found around this method suggests that the problem is usually a permissions issue, but the user that I'm logged in as is a Site Collection Administrator (ClientContext.Web.CurrentUser.IsSiteAdmin is true), so that shouldn't be the case with me.
I've tried passing in virtually every combination of PrincipalType and PrincipalSource, even ones that didn't make sense. I've also tried passing in ClientContext.Web.SiteUsers for the scope, and also null, both of which I've seen used in my searches, and that didn't turn up any results either.
Any help would be appreciated!
I figured it out. The ClientContext of the CSOM (Client Side Object Model) allows the developer to make multiple --unrelated -- queries. It queues up these queries and does not execute them until ExecuteQuery is called. Even though SearchPrincipals is a static method off of the Utility class, it still translates the method call into a query and queues it up. The method will always return an empty collection, but once you call ExecuteQuery on the ClientContext, that collection is then filled with the results of the search.
Also, another problem that I ran into immediately afterwards was that I was getting an error that seemed completely unrelated to my query when I called ExecuteQuery. It turns out that there was code that previously executed that queued up some queries, but it never executed them, so when I called ExecuteQuery, it executed those queries as well, and one of those was erroring. If you are getting an unexpected error, it's a good idea to see if there are other queued queries that haven't been executed yet. You can check the boolean property HasPendingRequest to help determine this.
Hopefully this answer saves other people a lot of time!
I want to confirm that, is this possible to customize Cakephp test suite(Unit Testing) message to our desired message on success & failed by default? It shows the following message
Now i want to customize time duration micro second to second by rounding function & also change Passed message to success OR my own message. How can i achieved this goal?
Thanx in Advance
Within ./lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php you can modify how the TestSuite reports stats.
I'm using a different version of CakePHP, but for me, Line 151 is this:
echo '<p><strong>Time:</strong> ' . $result->time() . ' seconds</p>';
You can take the $result->time() and run it through whatever PHP functions you want to get the output you're after. For that matter $result is set during your test cases is it not?
Just writing some tests for my CakePHP application and I am currently trying to work out the best way to test some functions in my models which end up saving data.
Should I just assertTrue or should I pull the data out of the database and assert the expected result against what is in the database?
There are some values that I have to generate programatically based on the users input so need to be sure they are write. Should I do a find operation within the test and check that the results of that are what I expect?
Use one of the expects to check what you save method returns. I assume you're not talking about save() because that is already tested within the core. So expect in your test whatever your method should return and see if it passes.
And yes, you can do a find within the test to check if your record was saved with the correct values. So find() it and expectEqual() on the result to whatever you expected.
By the way, it's always good to check the core tests to get an idea of how to test certain things or use mock objects. :)