-
Notifications
You must be signed in to change notification settings - Fork 214
Mojito Framework's Unit and Functional Tests
Mojito allows you to use npm test
to run tests and also
comes with the script run.js
that allows you to have more control over the test(s)
you want to run and where you want to write the test results.
Mojito uses the npm module Arrow, a testing framework that fuses together JavaScript, Node.js, PhantomJS, and Selenium. By running the built-in unit and functional tests, contributors can accelerate the merging of their pull request.
To run functional tests in a browser, follow the instructions in Running Tests with Selenium.
-
Clone the
develop
branch of Mojito:$ git clone https://github.com/yahoo/mojito.git --branch develop
-
Change to the
mojito
directory. -
Install the Mojito dependencies:
$ npm install
By default, Mojito uses the npm package phantomjs
for running tests.
You can use npm
to run functional and unit tests.
For more control over the running tests, such as running one test or specifying a
different location to write test results, use the wrapper script run.js
that
comes with Mojito.
-
From the
mojito
directory, run both the unit and functional tests withnpm
:$ npm test
-
To run only unit tests, use the following:
$ npm run-script unit
-
To run only functional tests, use the following:
$ npm run-script func
-
Change to the
mojito/tests
directory. -
To run the functional tests, you use the option
-u
and specify the path with the option--path
:$ ./run.js test -u --path unit --browser phantomjs
-
To run individual unit and functional tests, you pass the test descriptor (JSON test configuration file) to
run.js
.$ ./run.js test -f --path func --descriptor examples/newsboxes/newsboxes_descriptor.json --port 4000 --browser phantomjs
To run tests in a browser, you need the Selenium Server and browser drivers. Selenium Server comes with a driver for Firefox, so do not need to install the Firefox driver. To run tests in Chrome and other browsers, you will need to install the appropriate drivers. In the steps below, we'll just be using the default browser Firefox.
-
Install Selenium:
-
Start the Selenium server:
$ java -jar path/to/selenium-server-standalone-2.31.0.jar
-
Confirm Selenium is running by going to the following URL:
-
Shut down the Selenium server with
Ctrl-C
command.Warning
If you are not using Firefox v20 and the Selenium Standalone Server v2.31.0, you may run into backward compatibility issues. Please see the Platforms Supported by Selenium to learn what Selenium and browser versions are compatible.
-
Change to the
mojito/tests
directory. -
Start the Selenium server in the background:
$ java -jar path/to/selenium-server.jar &
-
Run the unit tests for the framework and client. As we mentioned before, the default browser is Firefox. To specify Chrome, you would add the option
--browser chrome
.$ ./run.js test -u --path unit --group fw,client,server --reuseSession
-
You can also run all the functional tests with the below command.
$ ./run.js test -f --path func --port 4000
The functional tests may take some time to complete, so you may want to terminate the tests with Ctl-C. Also, you do not need to specify the port with
--port
, but the command above does to show you the option. -
To run individual unit and functional tests, you pass the test descriptor to
run.js
.$ ./run.js test -f --path func --descriptor examples/newsboxes/newsboxes_descriptor.json --port 4000 --reuseSession
The command above runs the functional test for the
newsboxes
application. The--path
option indicates that the path to the test descriptor is located in thefunc
directory:func/examples/newsboxes/newsboxes_descriptor.json
Test results are written in both XML and JSON. You can specify the location to write test results or use the default location. In the following sections, we'll look at the default locations and the way to specify the location for unit and functional tests.
-
Default location when running
npm test
:- unit tests (XML) -
mojito/tests/unit/artifacts/arrowreport/arrow-report/arrow-test-summary.xml
- unit tests (JSON) -
mojito/tests/unit/artifacts/arrowreport/arrow-report/arrow-test-summary.json
- unit tests (XML) -
-
Use the option
--reportFolder
to specify the location to write test results:$ ./run.js test -u --path unit --browser phantomjs --reportFolder <dir>
-
Default Location when running
npm test
:- functional tests (XML) -
mojito/artifacts/arrowreport/arrow-report/arrow-test-summary.xml
- functional tests (JSON) -
mojito/artifacts/arrowreport/arrow-report/arrow-test-summary.json
- functional tests (XML) -
-
As with the test results for unit tests, use the option
--reportFolder
to specify the location to write test results.$ ./run.js test -f --path func --browser phantomjs --reportFolder <dir>