本文介绍了从XUL运行JavaScript代码的单元测试 - 什么和如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个XUL应用程序。它不是Firefox扩展,而是通过XULrunner使用的独立应用程序。我的目的是在我的开发过程中采用TDD,我正在考虑作为我的单元测试框架。无论如何我会尝试使用它,但没有太多关于测试XUL应用程序的文档。有些人谈论使用 - 但仅适用于Firefox插件 - 并且 - 如果您只想测试Mozilla。

I am writing an XUL application. It is not a Firefox extension but a standalone app to be used through XULrunner. My intention is to adopt TDD in my development process and I am looking at RhinoUnit as my unit testing framework. I will try to use it anyway but there is not much documentation about testing XUL applications. Some people talk about using UxU - but only for Firefox addons - and Mochitest - if you want to test Mozilla only.

我的问题是:是否有人用单元测试编写了一些XUL应用程序?你使用了什么工具,如果是我提到过的人,你是如何使用它的?

My question is: has someone written some XUL application with unit tests? What tool did you use and, if it is someone I have mentioned, how did you use it?

推荐答案

我成功使用Mochitest作为附加组件,它应该可以在XULRunner应用程序中以大致相同的方式使用。您需要,使用zip链接下载目录内容。将这些文件放在项目的某个位置,并将此目录映射到 chrome:// mochitest / content / 。将测试放入 chrome / 子目录中,有。您可以使用 runtests.py 使用 - chrome 命令行选项来启动测试,但我怀疑这将是没有调整脚本可能。在您的应用程序中打开 chrome://mochitest/content/harness.xul (作为XUL对话框或指定 -chrome chrome:// mochitest /应该也可以使用命令行中的content / harness.xul

I am successfully using Mochitest for an add-on, it should be usable in a XULRunner application in mostly the same way. You need the files under http://hg.mozilla.org/mozilla-central/file/tip/testing/mochitest/, use the "zip" link to download the directory contents. Put these files somewhere in your project and map this directory to chrome://mochitest/content/. Put your tests into the chrome/ subdirectory, there is extensive documentation on writing these tests. 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. 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.

编辑:我错了, zip链接下载整个存储库。我不知道从存储库获取特定目录的任何方法,最快的解决方案应该是运行 hg clone 从命令行获取整个存储库的副本。

Edit: I was wrong, the "zip" link downloads the entire repository. 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.

这篇关于从XUL运行JavaScript代码的单元测试 - 什么和如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:05