[英]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.