简体   繁体   English

使用Node.js在App Engine上进行本地单元测试

[英]Local unit testing on app engine with Node.js

We're starting a new app on Google App Engine with node.js. 我们正在使用node.js在Google App Engine上启动一个新应用。 We also decided to go with Cloud Datastore. 我们还决定使用Cloud Datastore。

I've found that in the other available languages you can do local unit testing: 我发现可以使用其他可用语言进行本地单元测试:

https://cloud.google.com/appengine/docs/java/tools/localunittesting https://cloud.google.com/appengine/docs/java/tools/localunittesting

I haven't found anything available for node.js. 我尚未找到可用于node.js的任何东西。 Do you know if there's something like the above link? 您知道上面的链接是否存在吗? If there's not, we're probably going to change to Java or Go. 如果没有,我们可能会改用Java或Go。

Thanks! 谢谢!

EDIT: I've just found this 编辑:我刚刚发现了这个

https://cloud.google.com/datastore/docs/tools/datastore-emulator https://cloud.google.com/datastore/docs/tools/datastore-emulator

Has anyone tried and knows if this could solve my problems? 有没有人尝试过并且知道这是否可以解决我的问题?

The difference between what you're looking at is about App Engine Standard vs App Engine Flexible (formerly known as Managed VMs). 您所看到的是App Engine Standard与App Engine Flexible(以前称为托管VM)之间的差异。 NodeJS is only supported on App Engine Flexible. 仅App Engine Flexible支持NodeJS。

App Engine Standard has some advantages (faster deployer times, ability to "scale to zero" so you pay nothing for idle apps), but it's much less flexible in that many libraries are not available in the runtimes and so you rely more heavily on App Engine APIs. App Engine Standard具有一些优点(更快的部署时间,能够“缩放为零”的能力,因此您无需为空闲的应用程序支付任何费用),但灵活性较差,因为运行时中没有许多库,因此您更加依赖App引擎API。 To provide a way to test it locally, the local development server was provided. 为了提供一种在本地进行测试的方法,提供了本地开发服务器。

Standard supports Python, Java, Go, and PHP. Standard支持Python,Java,Go和PHP。 However, even with those languages, you still might choose Flexible if you want to do something like use Java 8, Python 3, or custom libraries like imagemagick. 但是,即使使用这些语言,如果要执行诸如使用Java 8,Python 3或自定义库(如imagemagick)之类的操作,仍可以选择“灵活”。

App Engine Flexible is a pretty different product, although on the surface it looks similar since it has similar tooling and configuration, and they are both scalable platform-as-a-service products. App Engine Flexible是一种完全不同的产品,尽管表面上看起来很相似,因为它具有相似的工具和配置,并且它们都是可扩展的平台即服务产品。 But the concept is that you bring whatever environment you're familiar with it, and it runs it in a container (which is hidden from you. unless you use Custom runtimes to builds your own Docker runtime for it). 但是概念是,您可以带入您熟悉的任何环境,并在容器中运行它(对您而言是隐藏的。除非您使用Custom运行时为其构建自己的Docker运行时)。

Since you're bringing your standard development environment to App Engine, the idea is you test your Node app the same way you would test any other Node app, and run it like you would run other local Node projects locally. 由于您要将标准开发环境引入App Engine,因此您的想法是,以与测试其他任何Node应用程序相同的方式测试Node应用程序,并像在本地运行其他本地Node项目一样运行它。 There's not supposed to be too much special about the App Engine flexible environment, by design, so there's no need for a special local testing server. 从设计上讲,App Engine灵活环境不应有太多特殊之处,因此不需要特殊的本地测试服务器。

However, if you're using Cloud Datastore, emulators are provided so you can run tests more quickly and without paying any money. 但是,如果您使用的是Cloud Datastore,则提供了模拟器,因此您可以更快地运行测试而无需支付任何费用。 So the emulator is definitely what you're looking for to do local unit tests. 因此,仿真器绝对是您进行本地单元测试所需要的。 If you have any problems or issues with it, you should followup with more questions on Stack Overflow. 如果您有任何疑问或问题,则应该在堆栈溢出方面跟进更多的问题。

If you haven't seen already, there is a Getting Started with Node app that uses App Engine Flexible, and demonstrates a variety of tasks using Cloud Datastore, as well as MongoDB and CloudSQL (managed MySQL). 如果您还没有看到,那么有一个使用App Engine Flexible的Node入门应用程序,并使用Cloud Datastore以及MongoDB和CloudSQL(托管的MySQL)演示了各种任务。

https://github.com/googlecloudplatform/nodejs-getting-started https://github.com/googlecloudplatform/nodejs-getting-started

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

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