Google App Engine的集成测试(Java) [英] Integration tests for Google App Engine (java)

查看:123
本文介绍了Google App Engine的集成测试(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的GAE / j应用程序开发一些有效的集成测试。我熟悉 https://developers.google.com/appengine/docs/java/tools/localunittesting - 这些工具非常适合小型单元测试。我现在对开发测试实际Web请求的集成测试感兴趣。例如,我想测试web.xml是否将servlet和过滤器映射到期望的URL,并测试我的JSP生成了我期望的结果。

I'm trying to develop some effective integration tests for my GAE/j application. I'm familiar with https://developers.google.com/appengine/docs/java/tools/localunittesting -- these tools are great for small unit tests. I'm now interested in developing integration tests that test actual web requests. For example, I'd like to test that web.xml is mapping servlets and filters to the expected URLs and test that my JSPs generate what I expect.

我的目标是在JVM内部创建一个本地开发服务器,我可以发起请求。不过,我愿意接受其他整合策略。正如我上面所说的,我只是想有效地测试JSP生成和其他请求级功能。

My aim was to bring up a local development server inside the JVM, which I could fire requests against. I'm open to other integration strategies, though; as I say above, I just want to effectively test JSP generation and other request-level features.

我已经设法使用DevAppServerFactory来启动开发服务器JVM。但是,它生成的DevAppServer似乎使用主JVM中的单独类加载器。这使得测试更具挑战性 - 我不能使用任何本地单元测试Local * TestConfig类来控制此服务器的行为。同样,我不能通过例如滚动自己的钩子来修改行为。静态,因为我可以在测试工具中修改的静态数据与DevAppServer正在查看的静态数据不同。这使得跳过当前测试不重要的功能(例如需要登录),注入失败,注入模拟等等,这是非常具有挑战性的。这真的限制了我可以完全有效地测试我的代码。

I've managed to use DevAppServerFactory to start a development server in the same JVM. However, it appears that the DevAppServer this generates uses a separate classloader from the main JVM. This makes testing a lot more challenging--I can't use any of the local unittesting Local*TestConfig classes to control behavior of this server. Similarly, I can't "roll my own" hooks for modifying behavior via e.g. statics, since the statics I can mutate in the test harness aren't the same statics the DevAppServer is looking at. This makes it challenging to skip features not central to the current test (e.g. requiring login), to inject failures, to inject mocks, etc. This really limits how completely and efficiently I can test my code.

我发现网络上的文档实际缺乏与App Engine的集成测试。我确信有人已经这样做过了......有没有可以分享的任何提示或资源?

I've found a real dearth of documentation on the web for integration testing with App Engine. I'm sure someone has done this before...are there any tips or resources out there you can share?

推荐答案

基本上,你需要做两件事:

Basically, you need to do two things:


  1. 添加两个servlet(或其他),必须仅在测试期间启用 strong>,它允许您远程调用助手的设置和拆卸。

  2. 以完全单线程的方式为您的servlet引擎提供服务请求。这是必要的,因为由于某些原因,Helper类Google仅在当前线程中生效。

  1. Add two servlets (or whatever), which must be only enabled during testing, which allow you to invoke setup and teardown on the helper remotely.
  2. Make your servlet engine serve requests in a completely single-threaded way. This is needed because for some reason, the Helper class Google provides only takes effect in the current thread.

这篇关于Google App Engine的集成测试(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆