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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, SSR, i try to wrte test cases as in code.google.com/p/gwt-test-utils/wiki/Events, now am getting com.google.gwt.junit.JUnitFatalLaunchException Compilation error in test class.
You should ideally retag with gwt-test-utils if that is available or mention that in Your question. Refer to latest documentation here github.com/gwt-test-utils/gwt-test-utils/wiki/…. 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.
will you please check out the updated question, i didn't get solved it.
You might be missing a inherits tag for com.googlecode.gwt.test.utils.GwtReflectionUtils
i tried like <inherits name='com.googlecode.gwt.test.utils.GwtReflectionUtils'/> 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'
|
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.

1 Comment

Its okay to close the question by accepting your own answer. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.