我有一个GWT复合组件,有两个textBox,想为它编写测试用例。他们每个人都有变更处理程序,我想知道如何将复制事件发送到复合组件类中的精确组件。
编辑: 我的测试代码看起来像这样,
@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 Test运行它时出现错误: 在控制台
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。
答案 0 :(得分:1)
我不确定您对单元测试小部件的方法是否正确。
在这种情况下,理想情况下应设置值(触发内部更改事件)并测试更改处理程序中编写的代码是否已执行。
示例 - 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
如果您坚持触发更改事件,可以参考GWT示例 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
答案 1 :(得分:0)
我通过以下方式解决了问题: 扩展 GwtTest 而不是 GWTTestCases 并在 META-INF 文件夹中添加一个值为“ com.rubirules.uibuilder.UIBuilder = gwt-module ”的gwt-test-util.property文件,该文件夹是在测试包内。