MozUnit with XULRunner

14 views
Skip to first unread message

Jeff Webster

unread,
Jul 20, 2009, 1:39:38 PM7/20/09
to MozLab
We think MozUnit will really help us test our new XULRunner
application. However, as of right now I am unable to successfully
import any of our javascript code modules into our MozUnit tests. As
just suggested, we have our javascript code broken into modules,
loadable by the Components.utils.import function. We wish to unit
test those modules.

Our first minor issue was in actually attaching the MozUnit test
script file to one of our code modules directly using the
Components.utils.import function, but ran into two problems:
1) MozUnit is not part of our application, and as such has no concept
of the resource bindings defined in our application's chrome manifest
file.
2) The Components.utils.import function seems to not be available at
all, given by the following error in MozUnit:

Run failed. [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXPCComponents_Utils.import]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location "JS frame ::
chrome://mozunit/content/ui.js -> file:///irrelevant/path/test/mozUnit.js
:: <TOP_LEVEL> :: line 4" data: no]

We were able to get around this by using the loadSubScript
functionality, but it's not ideal since it hard-codes the path to the
code module instead of using chrome's url mapping capability already
defined in our manifest.

Our major issue is related. Once we actually had the code module
imported using loadSubScript, we immediately recognized it was
unusable as is in MozUnit because our code modules import each other
as necessary. Upon running, MozUnit reported the following error:

Run failed. [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXPCComponents_Utils.import]" nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)" location "JS frame ::
chrome://mozunit/content/ui.js -> file:///irrelevant/path/test/mozUnit.js
-> file:///irrelevant/path/chrome/modules/config.js :: <TOP_LEVEL> ::
line 11" data: no]

Our question is how do we get MozUnit to read our code modules which
use Components.utils.import to load each other?

Thanks, and we love what we so far -- we just hope we'll be able to
use it!

--Jeff

Massimiliano Mirra

unread,
Jul 24, 2009, 4:28:31 PM7/24/09
to moz...@googlegroups.com
Hi Jeff,

I myself haven't been using MozUnit for a while so please take the
following with a pinch of salt, but you could include MozUnit in your
application (put the XPI under its extensions/ directory) and then run
your app with:

xulrunner /path/to/application.ini -mozunit-run file:///tmp/mytest.js

m.
Reply all
Reply to author
Forward
0 new messages