在已编译的模块上运行 GWTTestCase
我有一个自动构建脚本,其中涉及在生产模式下对一些 GWT 模块进行单元测试。看来,当这些测试运行时,它们会重新编译 GWT 模块。
但是,在构建脚本的早期,我已经编译了模块。这显然是浪费精力。有谁知道有什么方法可以在已编译的模块上测试 GWTTestCase 在生产模式下运行吗?
我不介意丢失堆栈跟踪或任何信息,因为构建服务器仅通知开发人员哪些测试失败,并希望他们在自己的环境中进行调试。
I have an automated build script which involves unit testing of some GWT Modules in production mode. It appears that when these tests are run, they recompile the GWT module.
However, earlier in the build script, I have already compiled the modules. This is an obvious waste of effort. Does anybody know of any way to test a GWTTestCase to run in production mode, on modules that were already compiled.
I don't mind losing stacktraces or any information, because the build server only informs developers of which tests fails, and expects them to debug in their own environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将对您有所帮助。
测试基础架构中的主要类是 JUnitShell。要控制测试执行方式的各个方面,您必须将参数传递给此类。参数不能直接通过命令行传递,因为普通命令行参数直接传递到 JUnit 运行程序。相反,定义系统属性 gwt.args 以将参数传递给 JUnitShell。
例如,要在生产模式下运行测试(即,在将测试编译成 JavaScript 后运行测试),请在调用 JUnit 时将 -Dgwt.args="-prod" 声明为 JVM 参数。要获取受支持选项的完整列表,请声明 -Dgwt.args="-help" (而不是运行测试,而是将帮助打印到控制台)。
在生产模式下运行测试
使用 webAppCreator 工具时,您可以在开发模式或生产模式下启动测试。确保在两种模式下进行测试 - 尽管很少见,但 Java 和 JavaScript 之间存在一些差异,可能会导致您的代码在部署时产生不同的结果。
如果您决定从命令行运行 JUnit TestRunner,则必须添加一些附加参数以使单元测试在生产模式下运行。默认情况下,在开发模式下运行的测试在 JVM 中作为普通 Java 字节码运行。要覆盖此默认行为,您需要将参数传递给 JUnitShell
-Dgwt.args="-prod"
This will be helpful for you
The main class in the test infrastructure is JUnitShell. To control aspects of how your tests execute, you must pass arguments to this class. Arguments cannot be passed directly through the command-line because normal command-line arguments go directly to the JUnit runner. Instead, define the system property gwt.args to pass arguments to JUnitShell.
For example, to run tests in production mode (that is, run the tests afer they have been compiled into JavaScript), declare -Dgwt.args="-prod" as a JVM argument when invoking JUnit. To get a full list of supported options, declare -Dgwt.args="-help" (instead of running the test, help is printed to the console).
Running your test in Production Mode
When using the webAppCreator tool, you get the ability to launch your tests in either development mode or production mode. Make sure you test in both modes - although rare, there are some differences between Java and JavaScript that could cause your code to produce different results when deployed.
If you instead decide to run the JUnit TestRunner from command line, you must add some additional arguments to get your unit tests running in production mode. By default, tests run in development mode are run as normal Java bytecode in a JVM. To override this default behavior, you need to pass arguments to JUnitShell
-Dgwt.args="-prod"
好吧,我找到了一个解决方案,但它并不优雅。我修改了
JUnitShell.maybeCompileForWebMode
方法,您应该添加 VM 参数-Dcompile=false
以防止在运行单元测试时进行编译。您可以从此处获取 JUnitShell 的修改版本。Well, I found a solution, but it is not elagant. I modified
JUnitShell.maybeCompileForWebMode
method, you should add VM argument-Dcompile=false
to prevent compilation while running unit tests . You can get modified version of JUnitShell from here .