如何在 GWT 中运行 python Google App Engine 开发服务器 (dev_server.py) 进行单元测试?
因此,我有一个 GWT 客户端,它与 Python Google App Engine 服务器交互。客户端向服务器请求资源,服务器以 JSON 形式响应。很简单,没有 RPC 或类似的东西。我正在使用 Eclipse 开发我的 GWT 代码。
我有想要运行的 GWTTestCase 测试。不幸的是,我不知道如何实际让谷歌应用程序引擎服务器在每个测试中运行。我有一个好主意,尝试从命令行启动应用程序引擎服务器,但这当然行不通,因为 Process 和 ProcessBuilder 不是 GWT 开发工具包实际包含的类。
package com.google.gwt.sample.quizzer.client;
import java.io.IOException;
import java.lang.ProcessBuilder;
import java.lang.Process;
import com.google.gwt.junit.client.GWTTestCase;
public class QuizzerTest extends GWTTestCase {
public String getModuleName() {
return "com.google.gwt.sample.quizzer.Quizzer";
}
public void gwtSetUp(){
ProcessBuilder pb = new ProcessBuilder("dev_appserver.py",
"--clear_datastore",
"--port=9000",
"server_python");
try {
p = pb.start();
} catch (IOException e) {
System.out.println("Something happened when starting the app server!");
}
public void gwtTearDown(){ p.destroy(); }
public void testSimple() {
//NOTE: do some actual network testing from the GWT client to GAE here
assertTrue(true);}
}
编译此文件时出现以下错误:
[ERROR] Line 21: No source code is available for type java.lang.Process; did you forget to inherit a required module?
[ERROR] Line 30: No source code is available for type java.lang.ProcessBuilder; did you forget to inherit a required module?
正如您在下面看到的,我基本上希望每次测试都是这样:
- 启动我的 GAE 服务器的数据存储空实例
- ,针对此服务器实例在网络上运行测试。
- 停止服务器
- 当然,将测试结果报告给我。
有人有这样做的好方法吗?欢迎部分解决方案!黑客也很好。也许可以通过编辑“.launch”配置文件来解决这个问题?唯一重要的标准是我想针对我的实际 GAE Python 服务器“单元测试”我的 GWT 代码部分。
谢谢。
So, I have a GWT client, which interacts with a Python Google App Engine server. The client makes request to server resources, the server responds in JSON. It is simple, no RPC or anything like that. I am using Eclipse to develop my GWT code.
I have GWTTestCase test that I would like to run. Unfortunately, I have no idea how to actually get the google app engine server running per test. I had the bright idea below of trying to start the app engine server from the command line, but of course this does not work, as Process and ProcessBuilder are not classes that the GWT Dev kit actually contains.
package com.google.gwt.sample.quizzer.client;
import java.io.IOException;
import java.lang.ProcessBuilder;
import java.lang.Process;
import com.google.gwt.junit.client.GWTTestCase;
public class QuizzerTest extends GWTTestCase {
public String getModuleName() {
return "com.google.gwt.sample.quizzer.Quizzer";
}
public void gwtSetUp(){
ProcessBuilder pb = new ProcessBuilder("dev_appserver.py",
"--clear_datastore",
"--port=9000",
"server_python");
try {
p = pb.start();
} catch (IOException e) {
System.out.println("Something happened when starting the app server!");
}
public void gwtTearDown(){ p.destroy(); }
public void testSimple() {
//NOTE: do some actual network testing from the GWT client to GAE here
assertTrue(true);}
}
I get the following errors when compiling this file:
[ERROR] Line 21: No source code is available for type java.lang.Process; did you forget to inherit a required module?
[ERROR] Line 30: No source code is available for type java.lang.ProcessBuilder; did you forget to inherit a required module?
As you can see below, I basically want it to be the case that per test it:
- Starts a datastore-empty instance of my GAE server
- runs the test across the network, against this server instance.
- Stop the server
- Of course, report the result of the test back to me.
Does anyone have a good way of doing this? Partial solutions are welcome! Hacks are fine as well. Maybe some progress on this problem could be made by editing the ".launch" config file? The only important criteria is that I would like to "unit test" portions of my GWT code against my actual GAE Python server.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议为此创建一个 Ant 目标 - 请查看此页面 获取 GWT 的完整 ant 构建文件。
然后,作为测试目标的第一行,添加启动服务器的执行任务。请在此处查找 exec 文档。
然后在 IDE 中设置该 ant 任务。这样,无论您从何处运行测试,您都可以在测试之前运行服务器,并且如果需要,可以将其集成到构建过程中。
I would recommend creating an Ant target for this - take a look at this page for the full ant build file for GWT.
Then, as the first line of the testing target, add an execution task to start the server. Look here for exec docs.
Then set up that ant task in your IDE. This way you get the server running before your tests irrespective of where you run the tests from, and it can be integrated into your build process if you want.