我使用GWT RequestBuilder,爲了測試目的,我想在服務器中加載json文件。 它與DevMode完美協作,但在GWTTestCase中拋出404錯誤。GWT:單元測試時出現404錯誤RequestBuilder
隨着RPC,有一個修補程序添加<servlet path=".." class="..."/>
,但我可以做什麼與靜態內容?
,我可以很容易地使用@TextResource
,但它不是我的單元測試(這實際上是一個functionnal測試)
我使用GWT RequestBuilder,爲了測試目的,我想在服務器中加載json文件。 它與DevMode完美協作,但在GWTTestCase中拋出404錯誤。GWT:單元測試時出現404錯誤RequestBuilder
隨着RPC,有一個修補程序添加<servlet path=".." class="..."/>
,但我可以做什麼與靜態內容?
,我可以很容易地使用@TextResource
,但它不是我的單元測試(這實際上是一個functionnal測試)
靜態資源可以通過把它們放在the module's public path被捆綁與模塊的目標。
我用過(再次)托馬斯的答案來解決問題。我的模塊是io.robusta.fora.comments.Comment.gwt.xml
,我已將我的user.json文件放在io.robsuta.fora.comments.resources
包中。
我有這麼在Comment.gwt.xml文件中加入:<public path="resources"/>
然後GWTTestCase很簡單:
public class GwtRestClientTest extends GWTTestCase{
@Override
public String getModuleName() {
return "io.robusta.fora.comments.Comments";
}
public void testGET(){
String base = GWT.getModuleBaseURL();
System.out.println(base); //-> http://192.168.0.10:53551/io.robusta.fora.comments.Comments.JUnit/
GwtRestClient client = new GwtRestClient(base); //base url
AsyncCallback<String> cb = new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
System.out.println(result);//->{id:1,email:"[email protected]"}
finishTest();
}
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
};
client.GET("user.json", null, cb);//fetch my json file with no params
delayTestFinish(3000);
}
}
注:如果你想從中超開發模式來源加載JSON文件,那麼你可以用'GWT.getModuleBaseForStaticFiles()'替換'GWT.getModuleBaseURL()'。我會更新文檔(如果我在忘記它之前找到時間)。 –
https://gwt-review.googlesource.com/4340如果您認爲它可以得到增強,請隨時發表評論。 –