canmove, Confirmed users
737
edits
No edit summary |
|||
| Line 25: | Line 25: | ||
A package is defined as such by the presence of a file called "package.json" in the root directory. Among other things, "package.json" includes an string called "tests" which describes where the package test suites live. If this is not defined, the default is the "tests" or "test" directory under the package root. | A package is defined as such by the presence of a file called "package.json" in the root directory. Among other things, "package.json" includes an string called "tests" which describes where the package test suites live. If this is not defined, the default is the "tests" or "test" directory under the package root. | ||
So if you navigate to a package's root directory (containing a package.json file) and execute "cfx test", cfx will: | So if you navigate to a package's root directory (containing a package.json file) and execute "cfx test", <code>cfx</code> will: | ||
# initialize the tests directory using the "tests" value inside "package.json", or the top-level "tests/" or "test" directory | # initialize the tests directory using the "tests" value inside "package.json", or the top-level "tests/" or "test" directory | ||
| Line 94: | Line 94: | ||
test-module.js test-private-browsing.js test-windows.js | test-module.js test-private-browsing.js test-windows.js | ||
This isn't ideal if you only want to test a single module, so you can use the <code>-f</code> option to cfx to filter the set of tests to run. This option takes a regex and runs only the test suites whose names match the regex. This example runs only the tests for the "clipboard" module: | This isn't ideal if you only want to test a single module, so you can use the <code>-f</code> option to <code>cfx</code> to filter the set of tests to run. This option takes a regex and runs only the test suites whose names match the regex. This example runs only the tests for the "clipboard" module: | ||
(addon-sdk)~/mozilla/addon-sdk/packages/addon-kit > cfx test -f clipboard -v | (addon-sdk)~/mozilla/addon-sdk/packages/addon-kit > cfx test -f clipboard -v | ||
| Line 127: | Line 127: | ||
Program terminated successfully. | Program terminated successfully. | ||
=== cfx testcfx === | == cfx testcfx == | ||
<code>cfx testcfx</code> tests the <code>cfx</code> tool itself. <code>cfx</code> is written in Python, and <code>testcfx</code> uses Python's <code>unittest</code> framework. | |||
<code>cfx</code> test code is implemented by a collection of Python modules under python-lib/cuddlefish/tests. Each module implement defines a subclass of the unittest module's [http://docs.python.org/library/unittest.html#unittest.TestCase TestCase] class, and implements one or more test functions, each of which begins with the string "test". For example, here's what the "test_rdf" module looks like: | |||
(addon-sdk)~/mozilla/addon-sdk > cd python-lib/cuddlefish/tests | |||
(addon-sdk)~/mozilla /addon-sdk/python-lib/cuddlefish/tests > more test_rdf.py | |||
import unittest | |||
import xml.dom.minidom | |||
from cuddlefish import rdf | |||
class RDFTests(unittest.TestCase): | |||
def testBug567660(self): | |||
obj = rdf.RDF() | |||
data = u'\u2026'.encode('utf-8') | |||
x = '<?xml version="1.0" encoding="utf-8"?><blah>%s</blah>' % data | |||
obj.dom = xml.dom.minidom.parseString(x) | |||
self.assertEqual(obj.dom.documentElement.firstChild.nodeValue, | |||
u'\u2026') | |||
self.assertEqual(str(obj).replace("\n",""), x.replace("\n","")) | |||
<code>cfx testcfx</code> builds a [http://docs.python.org/library/unittest.html#unittest.TestSuite TestSuite] out of all the test cases it finds, then uses [http://docs.python.org/library/unittest.html#unittest.TextTestRunner TestTestRunner] to execute them. | |||