使用 Google Web Toolkit 进行 jUnit 测试
我希望能够通过在我的应用程序中链接到它们来运行一组单元测试(例如,我希望能够单击一个链接并让它运行一组 jUnit 测试)。问题是 GWT 和 jUnit 似乎并不是为这种功能而设计的——只有在构建时才能运行看起来的测试。
我希望能够将测试代码包含在我的应用程序中,并从 onModuleLoad
运行一组测试。
我尝试实例化一个测试对象:
StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();
但我得到: com.google.StockWatcher.client.StockWatcherTest 类型没有可用的源代码; 即使我专门包含该模块。
有人知道如何做到这一点吗?我只是希望能够在浏览器中显示测试结果。
I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests). The problem is that GWT and jUnit don't seem to be designed for this capability -- only at build time can you run the tests it seems.
I would like to be able to include my test code in my application and, from onModuleLoad
for example, run a set of tests.
I tried to just instantiate a test object:
StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();
but I get:
No source code is available for type com.google.StockWatcher.client.StockWatcherTest;
even though I include the module specifically.
Would anyone know a way to do this? I just want to be able to display the test results within the browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试使用 JUnit 测试 GWT 中的 UI 元素,遗憾的是您可能不会这样做。 JUnit 测试仅限于 RPC 和非 UI 客户端测试。请参阅此帖子< /a> 有关 GWT jUnit 测试可以做什么和不能做什么的精彩讨论。
如果您不尝试测试 UI 元素,而是尝试使用测试值注入 RPC 代码或客户端逻辑(因此您希望能够单击链接并运行一组 JUnit 测试),那么您应该遵循 testearly.com 中的以下指南: 测试 GWT使用 JUnit。简而言之,您应该确保您正在测试的方法不包含任何 UI 元素,并且如果您正在测试的方法本质上是异步的,则必须添加一个计时器。
在 2.0 中,添加了 HTMLUnit。您可能希望使用它,而不是每次想要测试时都启动浏览器。
If you are trying to test UI elements in GWT using JUnit, unfortunately you may not do so. JUnit testing is limited to RPC and non-UI client-side testing. See this thread for a great discussion on what you can and cannot do with GWT jUnit testing.
If you are not trying to test UI elements, but are instead trying to inject your RPC code or client-side logic with test values (hence why you want to be able to click on a link and run a set of JUnit tests), then you should follow the following guide from testearly.com: Testing GWT with JUnit. In short, you should make sure that the method you are testing does not include any UI elements and if the method you are testing is asynchronous in nature, you must add a timer.
In 2.0, HTMLUnit was added. You may wish to use this instead of firing up a browser each time you wish to test.