1

標準の GWT の例を使用して、新しい Web アプリケーション プロジェクトを作成します。次に、次のテスト クラスで greetingserviceimpl をテストします。どこに問題があるのか​​わからない。プロジェクトもアップロードします: http://ul.to/1pz1989y

public class RPCTest extends GWTTestCase {

@Override
public String getModuleName() {
    // TODO Auto-generated method stub
    return "de.GreetingTest";
}

public void testGreetingAsync() {
    GreetingServiceAsync rpcService =  (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/GreetingTest.html?gwt.codesvr=127.0.0.1:9997");
    rpcService.greetServer("GWT User", new AsyncCallback<String>() {
        public void onFailure(Throwable ex) {                
            ex.printStackTrace();
            fail(ex.getMessage());              
        }
        public void onSuccess(String result) {
            assertNotNull(result);               
            finishTest();//
        }
    });
    delayTestFinish(1000);
}

}

新しくコンパイルされたユニットを検証しています 最初のパスでコンパイル エラーが発生した 1 つのユニットが無視されました。
-strict または -logLevel を TRACE または DEBUG に設定してコンパイルすると、すべてのエラーが表示されます。
[エラー] 17 行目: com.gdevelop.gwt.syncrpc.SyncProxy 型のソース コードがありません。必要なモジュールを継承するのを忘れましたか?
[エラー] タイプ 'de.client.RPCTest' が見つかりません
[エラー] ヒント: 以前のコンパイラ エラーにより、このタイプが使用できなくなった可能性があります
[エラー] ヒント: モジュールからの継承チェーンを確認してください。必要なモジュールを継承していないか、モジュールがソース パス エントリを適切に追加していない可能性があります

4

1 に答える 1

0

あなたの rpc サービスは非同期です - testGreetingAsync メソッドが戻るまでに終了しません。ただし、GWTTestCase (ただし、TestCase を拡張しているため、おそらくこれを変更する必要があります) はこれをサポートしていますdelayTestFinish。メソッドの最後で呼び出して、テストが非同期であることを示します。次に、finishTest成功したら呼び出します。

public class RPCtest extends GWTTestCase {
    public void testGreetingAsync() {
        GreetingServiceAsync rpcService =  (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/Tests.html?gwt.codesvr=127.0.0.1:9997");
        rpcService.greetServer("GWT User", new AsyncCallback() {
            public void onFailure(Throwable ex) {
                //indicate that a failure has occured
                ex.printStackTrace();
                fail(ex.getMessage());//something like this               
            }
            public void onSuccess(Object result) {
                //verify the value...
                assertNotNull(result);

                //Then, once sure the value is good, finish the test
                finishTest();//This tells GWTTestCase that the async part is done
            }
        });
        delayTestFinish(1000);//1000 means 'delay for 1 second, after that time out'
    }
}

更新された質問の編集:

テスト クラス 'de.RPCTest' がモジュール 'de.GreetingTest' に見つかりませんでした。そのタイプのコンパイル単位は見られませんでした

通常の GWT コードがclientパッケージに含まれている必要があるのと同様に、GWTTestCase コードもパッケージに含まれている必要があります。これも JavaScript として実行されるため、ブラウザー内にあるかのように適切にテストできます。エラーに基づいて、私はあなたの EntryPoint などが入っていると推測していますde.client- このテストもそこにあるはずです。

于 2012-09-26T23:35:24.537 に答える