简体   繁体   English

从 XUL 运行 JavaScript 代码的单元测试 - 什么和如何

[英]Running unit tests of JavaScript code from XUL - what and how

I am writing an XUL application.我正在编写一个 XUL 应用程序。 It is not a Firefox extension but a standalone app to be used through XULrunner.它不是 Firefox 扩展,而是通过 XULrunner 使用的独立应用程序。 My intention is to adopt TDD in my development process and I am looking at RhinoUnit as my unit testing framework.我的目的是在我的开发过程中采用 TDD,我将RhinoUnit作为我的单元测试框架。 I will try to use it anyway but there is not much documentation about testing XUL applications.无论如何我都会尝试使用它,但没有太多关于测试 XUL 应用程序的文档。 Some people talk about usingUxU - but only for Firefox addons - and Mochitest - if you want to test Mozilla only.有些人谈论使用UxU - 但仅适用于 Firefox 插件 - 和Mochitest - 如果您只想测试 Mozilla。

My question is: has someone written some XUL application with unit tests?我的问题是:有人用单元测试编写了一些 XUL 应用程序吗? What tool did you use and, if it is someone I have mentioned, how did you use it?你使用了什么工具,如果是我提到的人,你是如何使用它的?

You could try to have a look at Mozmill .您可以尝试看看Mozmill It is an addon that can be used for testing all Gecko based applications.它是一个插件,可用于测试所有基于 Gecko 的应用程序。
You can use it to test UI interface of your application.您可以使用它来测试应用程序的 UI 界面。
The documentation is quite ok and if you have any question you can try the dedicated mailing list.文档非常好,如果您有任何问题,可以尝试专用邮件列表。

I am successfully using Mochitest for an add-on, it should be usable in a XULRunner application in mostly the same way.我成功地将 Mochitest 用于附加组件,它应该可以在 XULRunner 应用程序中以几乎相同的方式使用。 You need the files under http://hg.mozilla.org/mozilla-central/file/tip/testing/mochitest/ , use the "zip" link to download the directory contents.您需要http://hg.mozilla.org/mozilla-central/file/tip/testing/mochitest/下的文件,使用“zip”链接下载目录内容。 Put these files somewhere in your project and map this directory to chrome://mochitest/content/ .将这些文件放在项目中的某个位置,并将 map 这个目录放到chrome://mochitest/content/中。 Put your tests into the chrome/ subdirectory, there is extensive documentation on writing these tests.将您的测试放入chrome/子目录,有大量关于编写这些测试的文档 You could use runtests.py with --chrome command line options to start the tests but I doubt that this will be possible without tweaking the script.您可以使用带有--chrome命令行选项的runtests.py来启动测试,但我怀疑这在不调整脚本的情况下是否可行。 Opening chrome://mochitest/content/harness.xul in your application (as a XUL dialog or by specifying -chrome chrome://mochitest/content/harness.xul on the command line) should do as well.在您的应用程序中打开chrome://mochitest/content/harness.xul (作为 XUL 对话框或通过在命令行上指定-chrome chrome://mochitest/content/harness.xul )也应该这样做。

Edit : I was wrong, the "zip" link downloads the entire repository.编辑:我错了,“zip”链接下载了整个存储库。 I don't know of any way to get a particular directory from the repository then, fastest solution should be running hg clone http://hg.mozilla.org/mozilla-central/ from the command line to get a copy of the entire repository.我不知道从存储库中获取特定目录的任何方法,最快的解决方案应该是从命令行运行hg clone http://hg.mozilla.org/mozilla-central/以获取整个副本存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM