The testbed provides stubs for App Engine services (in the original sense of the word, not, as used today, as a renaming of what used to be called App Engine modules) which let you control precisely the entire setup in which you unit-test your Python code meant to run in App Engine. It deals with App Engine only, and is optimal for small setups entirely under your control.
The datastore API (still in beta) is not specific to App Engine -- see https://cloud.google.com/datastore/docs/concepts/overview for a general overview of the product, and https://cloud.google.com/datastore/docs/client-libraries for more about it. The emulator tool complements the API by letting you test systems using the API (whether they're meant to run in App Engine, elsewhere, or a mix) typically in situations where persistence helps (you don't setup the datastore state anew for every test, so it can, if needed, be a pretty substantial state) -- essentially, integration tests, for the most part (though nothing stops you from using the emulator for unit tests, the testbed is usually handier for the latter if your code is meant to run in App Engine). Unit and integration tests are not mutually exclusive: to make your code highly reliable, you should cover it well with both kinds of tests. The testbed and the emulator give you the underlying tools to do exactly that. Alex On Fri, Jun 10, 2016 at 4:55 AM, Juan Antonio Fernández Sánchez < [email protected]> wrote: > > I'm really confused with the way to try Datastore in local. Please, give > me a minute to explain. > > I'm developing a app composed to few microservices like a only gae app. In > a parte of the app, I use the datastore. So when I run my app, I use the > development server and when I save something in the datastore calling some > method I can see perfectly the entity in the gae's admin web portal. > > Well, now, instead of calling directly to ndb library and his methods I've > built a small library over ndb to abstract his functionallity, then I can > call insertUser() instead of work directly with ndb. So, the problems > appear when I try test this small library that I built (I've written a > test.py file to do this). > At first, I thought that this does not can work because this test was > executing without the deveserver running. After I searched info about how > simulated the datastore in the local and I found this, but after I found > too the unittest in local with the stubs, and now I don't understand > nothing. > > I've tried both (gcloud datastore emulator and stub with unittest) and I > don't get do simple example: > I want test that a entity is saved in Datastore and after I want test that > I can read this entity > > I suppose that dev_server (in SDK) emulate the datastore (because I can > see the list of my entities there), but then, why use the datastore > emulator in local dev?, and then, why is necesary uses the stub to > datastore if we have a datastore emulator to do all test that I want? I > don't understand. > > I understand that maybe my question is more of concepts than code but I > need understand really right how is the best way to work with this. > > LocalDev Server --> > https://cloud.google.com/appengine/docs/python/tools/using-local-server > UnitTest with Stub --> > https://cloud.google.com/appengine/docs/python/tools/localunittesting > DataStore Emulator --> > https://cloud.google.com/datastore/docs/tools/datastore-emulator > > Thanks you so much, any help will be welcome :) > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/google-appengine. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-appengine/cd123e20-c5fc-4faa-8717-49ddd012bd22%40googlegroups.com > <https://groups.google.com/d/msgid/google-appengine/cd123e20-c5fc-4faa-8717-49ddd012bd22%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-appengine. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/CAE46Be9jPgCsWab_vXpLfxPkqUSwuwSVt91oj35EkChVGKpAgA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
