Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何从gwt单元测试用例访问dom元素?_Unit Testing_Gwt - Fatal编程技术网

Unit testing 如何从gwt单元测试用例访问dom元素?

Unit testing 如何从gwt单元测试用例访问dom元素?,unit-testing,gwt,Unit Testing,Gwt,我的问题是: 如何从gwt单元测试用例访问dom元素 我只有一个带有链接的静态html: <a href="#" id="my_button">jjj</a> 我将得到一个运行时异常(测试失败),因为elm是null 怎么了?我是否缺少任何初始化调用…?GWT中的单元测试不使用应用程序的主机页;他们使用com.google.gwt.junit.junit模块中的一个(或junit standards.html),该模块几乎为空 您必须“创建”测试运行的环境(在gwtSe

我的问题是: 如何从gwt单元测试用例访问dom元素

我只有一个带有链接的静态html:

<a href="#" id="my_button">jjj</a>
我将得到一个运行时异常(测试失败),因为
elm
null


怎么了?我是否缺少任何初始化调用…?

GWT中的单元测试不使用应用程序的主机页;他们使用
com.google.gwt.junit.junit
模块中的一个(或junit standards.html),该模块几乎为空


您必须“创建”测试运行的环境(在
gwtSetup
中或在测试方法开始时)。

关于如何设置测试环境以使用我设计的主机页的任何指针?
public void testButton() {
    Element elm = Document.get().getElementById("my_button");
    assertNotNull(elm);
}