简体   繁体   English

模拟 Bigquery 进行集成测试

[英]Mocking Bigquery for integration tests

While other interfaces are relatively easy to mock in my Java integration tests, I couldn't find a proper way of mocking Bigquery.虽然在我的 Java 集成测试中模拟其他接口相对容易,但我找不到模拟 Bigquery 的正确方法。

One possibility is to mock the layer I wrote on top of Bigquery itself, but I prefer mocking Bigquery in a more natural way.一种可能性是模拟我在 Bigquery 本身之上编写的层,但我更喜欢以更自然的方式模拟 Bigquery。 I'm looking for a limited, lightweight implementation, which allows defining the table contents, and supports queries using the standard API.我正在寻找一种有限的、轻量级的实现,它允许定义表内容,并支持使用标准 API 的查询。 Is there such a library?有这样的图书馆吗? If not, what alternative approaches are recommended?如果不是,建议使用哪些替代方法?

In unit testing it is perfectly fine to mock all external dependencies, and as long you are using interfaces to abstract out access to BigQuery client, mocking should not be an issue.在单元测试中,可以模拟所有外部依赖项,只要您使用接口抽象出对 BigQuery 客户端的访问,模拟就不是问题。

With integration testing I would rather get all my 3rd parties dependencies tested to the extend an application needs it.通过集成测试,我宁愿对所有 3rd 方依赖项进行测试以扩展应用程序需要它。

For instance one case would be an ETL which streams data from external sources to BigQuery, in this case an integration test needs to verify that all data is in BigQuery as expected, which means that verification stage needs to take into account repeated, and nested messages as required.例如,一种情况是将数据从外部源流式传输到 BigQuery 的 ETL,在这种情况下,集成测试需要验证所有数据是否按预期在 BigQuery 中,这意味着验证阶段需要考虑重复和嵌套的消息按要求。

Another case would an application that runs some business SQLs, in this case you would have populate BigQuery with some test data before applicaiton run, then the applicaiton needs to publishe the SQL output either as view/new table/or stream out of data out of for verification.另一种情况是运行一些业务 SQL 的应用程序,在这种情况下,您将在应用程序运行之前使用一些测试数据填充 BigQuery,然后应用程序需要将 SQL 输出发布为视图/新表/或流出数据用于验证。

There are already some libraries taking care of integration testing with datastores including BigQuery/NoSQL/SQL已经有一些库负责与数据存储的集成测试,包括 BigQuery/NoSQL/SQL

They would provide an easy solution for the cases described above and full support for SQL, dynamic macro/predicate etc ....它们将为上述情况提供简单的解决方案,并完全支持 SQL、动态宏/谓词等......

  1. Dsunit (go-lang) Dsunit (go-lang)
  2. JDsunit (java) JDsunit (java)
  3. Endly (language agnostic) Endly (语言不可知)

See more how to use endly for ETL and BiqQuery testing查看更多如何使用endly进行 ETL 和 BiqQuery 测试

If datastore integration test library is not an option for you and you are looking for just testing BigQuery client, the good news is that the client uses REST, so using network sniffers you can easy record what is being send back and forth, then you can use it in replayer.如果数据存储集成测试库不适合您,并且您只想测试 BigQuery 客户端,好消息是客户端使用 REST,因此使用网络嗅探器可以轻松记录来回发送的内容,然后您可以在播放器中使用它。 In order to redirect BigQuery from public BG endpoints to your replayer you would use http java proxy.为了将 BigQuery 从公共 BG 端点重定向到您的播放器,您将使用 http java 代理。

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

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