Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GWT Junit测试用例_Java_Gwt_Junit_Testcase - Fatal编程技术网

Java GWT Junit测试用例

Java GWT Junit测试用例,java,gwt,junit,testcase,Java,Gwt,Junit,Testcase,我想用GWT Junit测试RPC。我使用标准GWT示例并创建以下测试用例: public class TestGreetingService extends GWTTestCase { /** * Must refer to a valid module that sources this class. */ public String getModuleName() { return "com.TestGreeting"; } /** * This test will

我想用GWT Junit测试RPC。我使用标准GWT示例并创建以下测试用例:

public class TestGreetingService extends GWTTestCase {
/**
 * Must refer to a valid module that sources this class.
 */
public String getModuleName() {
    return "com.TestGreeting";
}   

/**
 * This test will send a request to the server using the greetServer method
 * in GreetingService and verify the response.
 */
public void testGreetingService() {
    // Create the service that we will test.
    GreetingServiceAsync greetingService = GWT
            .create(GreetingService.class);
    ServiceDefTarget target = (ServiceDefTarget) greetingService;
    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "TestGreeting/greet");

    // Since RPC calls are asynchronous, we will need to wait for a response
    // after this test method returns. This line tells the test runner to
    // wait
    // up to 10 seconds before timing out.
    delayTestFinish(20000);

    // Send a request to the server.
    greetingService.greetServer("GWT User", new AsyncCallback<String>() {
        public void onFailure(Throwable caught) {
            // The request resulted in an unexpected error.
            fail("Request failure: " + caught.getMessage());
        }

        public void onSuccess(String result) {
            // Verify that the response is correct.
            assertTrue(result.startsWith("Hello, GWT User!"));

            // Now that we have received a response, we need to tell the
            // test runner
            // that the test is complete. You must call finishTest() after
            // an
            // asynchronous test finishes successfully, or the test will
            // time out.
            finishTest();
        }
    });
}
}
公共类TestGreetingService扩展了GWTTestCase{
/**
*必须引用源于此类的有效模块。
*/
公共字符串getModuleName(){
返回“com.TestGreeting”;
}   
/**
*此测试将使用greetServer方法向服务器发送请求
*在问候服务中,并验证响应。
*/
public void testGreetingService(){
//创建我们将测试的服务。
GreetingServiceAsync greetingService=GWT
.create(GreetingService.class);
ServiceDefTarget=(ServiceDefTarget)问候服务;
target.setServiceEntryPoint(GWT.getModuleBaseURL()+“TestGreeting/greet”);
//由于RPC调用是异步的,我们需要等待响应
//此测试方法返回后。此行告诉测试运行程序
//等等
//在超时前最多10秒。
延迟测试完成(20000);
//向服务器发送请求。
greetServer(“GWT用户”,新的AsyncCallback()){
失败时的公共无效(可丢弃){
//请求导致意外错误。
失败(“请求失败:+catch.getMessage());
}
成功时的公共void(字符串结果){
//验证响应是否正确。
assertTrue(result.startsWith(“你好,GWT用户!”);
//现在我们已经收到了回复,我们需要告诉
//试车
//测试已完成。您必须在之后调用finishTest()
//一个
//异步测试成功完成,否则测试将失败
//暂停。
finishTest();
}
});
}
}
不幸的是,我遇到了以下错误:有人能帮我吗?我还上传了这个项目:goo.gl/UnFyt

 [WARN] 404 - POST /com.TestGreeting.JUnit/TestGreeting/greet (192.168.1XX.XX) 1427 bytes <br>
Request headers <br>
Host: 192.168.1XX.XX:53577 <br>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 <br> Firefox/3.0.19 <br>
Accept-Language: en-us <br>
Accept: */* <br>
Connection: Keep-Alive <br>
Referer: http://192.168.1XX.XX:53577/com.Test...8.1XX.XX:53572 <br>
X-GWT-Permutation: HostedMode <br>
X-GWT-Module-Base: http://192.168.1XX.XX:53577/com.TestGreeting.JUnit/ <br>
Content-Type: text/x-gwt-rpc; charset=utf-8 <br>
Content-Length: 181 <br>
Response headers <br>
Content-Type: text/html; charset=iso-8859-1 <br>
Content-Length: 1427 <br>
[WARN]404-POST/com.TestGreeting.JUnit/TestGreeting/greet(192.168.1XX.XX)1427字节
请求头
主机:192.168.1XX.XX:53577
用户代理:Mozilla/5.0(Windows;U;Windows NT 5.1;en-US;rv:1.9.0.19)Gecko/2010031422
Firefox/3.0.19
接受语言:en-us
接受:*/*
连接:保持活动状态
推荐人:http://192.168.1XX.XX:53577/com.Test...8.1XX.XX:53572
X-GWT-Permutation:HostedMode
X-GWT-Module-Base:http://192.168.1XX.XX:53577/com.TestGreeting.JUnit/
内容类型:text/x-gwt-rpc;字符集=utf-8
内容长度:181
响应标题
内容类型:text/html;字符集=iso-8859-1
内容长度:1427

如果收到404警告,则无法找到您的服务。 您的ServiceEntryPoint定义一定有问题

请尝试同步接口的@RemoteServiceRelativePath(“问候”)注释,或将setServiceEntryPoint更正为

    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "greet");
另外,请看一下DevGuide,其中的说明帮助我很好地习惯了GWT RPC服务:

谢谢!我必须在gwt.xml中添加“”