简体   繁体   English

单元测试为Google AppEngine灵活环境编写的python 3.x代码并使用Cloud Datastore Api

[英]Unit testing a python 3.x code written for Google AppEngine flexible environment and using Cloud Datastore Api

Is there a way to unit test a code which is using cloud datastore api and written for flexible environment? 有没有办法对使用云数据存储api并为灵活环境编写的代码进行单元测试? testbed seems to be tied up with standard environment and it looks like using emulator will require launching/closing emulator process which usually is a flaky way for unit tests. testbed似乎与标准环境捆绑在一起,看起来使用仿真器需要启动/关闭仿真器进程,这通常是单元测试的一种不稳定的方式。

We end up with end to end testing (launch you tests with real db in dev environment, for example) As we having tenant based application, each test run just creates new tenant and all operations performed in scope of this tenant, so, there should no any inconsistency here. 我们最终进行端到端测试(例如,在开发环境中使用真实数据库启动测试)当我们有基于租户的应用程序时,每个测试运行只创建新租户并且所有操作都在此租户的范围内执行,因此,应该这里没有任何不一致。 In the other hand, such solution is pretty slow. 另一方面,这种解决方案非常缓慢。

The solution above, is just the easiest one, I believe here. 上面的解决方案,这是最简单的解决方案,我相信这里。 Another option would be to split you code on db dependent parts and business logic part. 另一种选择是将代码拆分为数据库相关部分和业务逻辑部分。 In this case you will test only business logic part, and mock db dependency. 在这种情况下,您将仅测试业务逻辑部分,并模拟数据库依赖项。 But, as we've investigated such solution, we found that we have a lot of code that have one line of db write operation and 1-3 lines of business logic code. 但是,正如我们研究过这样的解决方案,我们发现我们有很多代码都有一行db编写操作和1-3行业务逻辑代码。 So, splitting such code on different levels would be meaningless for testing and maintenance. 因此,在不同级别上拆分此类代码对于测试和维护而言毫无意义。

I guess, the last option is more generic relatively previous one, is to mock db. 我猜,最后一个选项是比较先前的一个选项,就是模拟db。 For each module that uses db, before test it you should inject mocked database index, that defines some responses. 对于使用db的每个模块,在测试之前,您应该注入模拟数据库索引,该索引定义了一些响应。 But in this case it is easy to fall in realization testing, instead of behavioral testing, so again that will mean, that such testing becomes quite ineffective. 但在这种情况下,很容易陷入实现测试,而不是行为测试,所以再次意味着这样的测试变得非常无效。

I guess, this question is more generic about testing approaches, and not about actually datastore itself. 我想,这个问题对于测试方法更为通用,而不是实际上是数据存储本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python3x 的 Google Cloud Datastore 中的 UTF-8 字符串? - UTF-8 strings in the Google Cloud Datastore using Python3x? 是否有适用于Python 3.x的Google Data API(gdata)? - Is there a Google Data API (gdata) for Python 3.x? 如何使用非容器化工件使用bazel和google云部署灵活部署到appengine? - How to deploy to appengine flexible using bazel and google cloud deploy using non containerized artifact? 当其余部分用python 3.x编写时,是否可以在python 2.x中运行部分代码? - Is it possible to run parts of a code in python 2.x while the rest is written in python 3.x? 在IDEA的Python 3.x中使用单元测试中的参数 - Using parameters in unit tests in Python 3.x from IDEA 对 Zendesk API 的 GET 请求使用 Python 3.x 和 HTTP 代码 401 未授权失败 - GET requests to Zendesk API fail using Python 3.x with the HTTP code 401 Unauthorised 使用py.test在python中测试和调试数据存储区代码的问题 - problems with testing and debugging datastore code in python using py.test TypeError,回文测试(Python 3.x) - TypeError, Palindrome Testing (Python 3.x) 如何使用函数 Python 3.x 划分代码 - How to divide code using functions Python 3.x 如何在 python3 中使用 google-cloud-ndb 库在谷歌云数据存储上进行交易 - How to do transactions using on google cloud datastore using google-cloud-ndb library in python3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM