2013-01-02 43 views
0

我有一個GWT複合組件,有兩個文本框,想爲它編寫測試用例。他們每個人都有更改處理程序,我想知道如何將更改事件觸發到複合組件類中的確切組件。GWT compositC組件測試用例?

編輯: 我的測試代碼如下所示,

@Test 
    public void testValueChangesToOutOfRange(){ 
     DvCountUI count = new DvCountUI(15, "place holder", true); 
     count.specifyNormalRange(10, 30); 
     TextBox magnitude = GwtReflectionUtils.getPrivateFieldValue(count, "magnitude"); 
     assertTrue(true); 

    } 

,當我與GWT JUnit測試運行它我得到錯誤: 控制檯

Validating units: 
    Ignored 1 unit with compilation errors in first pass. 
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors. 
[ERROR] Errors in 'file:/D:/TRANSFER/asclepian/workspace/UIBuilder/src/com/rubirules/uibuilder/client/DvCountUITest.java' 
    [ERROR] Line 65: No source code is available for type com.googlecode.gwt.test.utils.GwtReflectionUtils; did you forget to inherit a required module? 
[ERROR] Unable to find type 'com.rubirules.uibuilder.client.DvCountUITest' 
    [ERROR] Hint: Previous compiler errors may have made this type unavailable 
    [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly 

,並在JUnit

JUnitFatalLaunchException 

我gwt.xml文件看起來像:

<module rename-to='uibuilder'> 
    <inherits name='com.google.gwt.user.User' /> 
    <inherits name='com.google.gwt.user.theme.clean.Clean' /> 
    <entry-point class='com.rubirules.uibuilder.client.UIBuilder' /> 
    <source path='client' /> 
    <source path='shared' /> 
</module> 

什麼錯嗎? 我還在項目庫中添加了gwt-test-utils jar。

回答

1

我不確定您的單元測試小部件的方法是否正確。

在這種情況下,您應該理想地設置值(觸發內部更改事件)並測試寫入更改處理程序的代碼是否得到執行。

示例 - TextBoxBaseTestBase.java
public void testValueChangeEvent() {}http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java

如果硬要改變射擊事件,你可以參考GWT樣品CreateEventTest.java

public void testTriggerChangeEvent() {}http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/user/client/ui/CreateEventTest.java

+0

謝謝,SSR,我嘗試測試用例,如http://code.google.com/p/gwt-test-utils/wiki/Events, 現在我正在獲取com.google.gwt.junit.JUnitFatalLaunchException測試類中的編譯錯誤。 – Dipak

+0

如果可用或在您的問題中提及,您應該最好使用gwt-test-utils進行重新授權。請參閱最新文檔https://github.com/gwt-test-utils/gwt-test-utils/wiki/Browser-simulation。它不是理想的情況。堅持基本的單元測試策略和「Follo GWT團隊」。此外,我寧願依賴Selenium + GWTTestCase策略,而不是其他任何第三方工具。 – SSR

+0

你會不會檢查出最新的問題,我沒有得到解決。 – Dipak

0

我得到有效解決的事情:擴展GwtTest,而不是GWTTestCases 並增加了gwt-test-util.property文件與價值 「com.rubirules.uibuilder.UIBuilder = GWT模塊」 ,在META-INF文件夾裏面是測試包。

+0

它可以通過接受你自己的答案來結束這個問題。 :) – SSR