0

i had a GWT composite component, with two textBox, want to write test cases for it. Each of them had change handler, i want to know how can i fire a change event to exact component in the composite component class.

EDITED: my test code looks like this,

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

    }

and when i run it with GWT Junit Test am getting ERROR: in console

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

and in junit

JUnitFatalLaunchException

my gwt.xml file looks like:

<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>

whats wrong here? also i added gwt-test-utils jar in project library.

Dipak
  • 6,532
  • 8
  • 63
  • 87

2 Answers2

1

I am not sure whether your approach towards unit testing widget is correct.

In this scenario you should ideally be setting value (triggering the internal change event) and testing whether the code written in the change handler get executed.

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

If you insist on firing change event you can refer to GWT sample CreateEventTest.java

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

appbootup
  • 9,537
  • 3
  • 33
  • 65
  • Thanks, SSR, i try to wrte test cases as in http://code.google.com/p/gwt-test-utils/wiki/Events, now am getting com.google.gwt.junit.JUnitFatalLaunchException Compilation error in test class. – Dipak Jan 02 '13 at 14:06
  • You should ideally retag with gwt-test-utils if that is available or mention that in Your question. Refer to latest documentation here https://github.com/gwt-test-utils/gwt-test-utils/wiki/Browser-simulation. Its not ideal scenario. Stick to basic Unit Testing strategy and "Follo GWT Team" . Also, i would rather rely on Selenium + GWTTestCase strategy than any other third party tool. – appbootup Jan 02 '13 at 14:15
  • will you please check out the updated question, i didn't get solved it. – Dipak Jan 03 '13 at 05:17
  • You might be missing a inherits tag for com.googlecode.gwt.test.utils.GwtReflectionUtils – appbootup Jan 03 '13 at 05:28
  • i tried like but result is, Unable to find 'com/googlecode/gwt/test/utils/GwtReflectionUtils.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source? Unexpected exception while processing element 'inherits' – Dipak Jan 03 '13 at 05:43
  • SSR , i got solved things by extending GwtTest instead of GWTTestCases. It works fine with GwtReflectionUtils. I didn't added any inherits tag and but added a gwt-test-util.property file with a value "com.rubirules.uibuilder.UIBuilder = gwt-module", in the META-INF folder which is inside test package. Anyway thanks for the instructions. – Dipak Jan 03 '13 at 08:15
  • Good. I would not recommend low level unit test simulating events. They simply do not assure anything Event flow is vastly complex is real world browser and the best way to use GWT teams approach of Unit Tests with Selenium for integrity tests. – appbootup Jan 03 '13 at 08:20
  • Thanks, now am using these to test my composite components. When it comes to complete form will use Selenium for that. :) – Dipak Jan 03 '13 at 08:30
0

I got solved things by : extending GwtTest instead of GWTTestCases and adding a gwt-test-util.property file with a value "com.rubirules.uibuilder.UIBuilder = gwt-module", in the META-INF folder which is inside test package.

Dipak
  • 6,532
  • 8
  • 63
  • 87