Mojito Framework's Unit and Functional Tests

Joe Catera edited this page Jan 7, 2014 · 13 revisions

Overview

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.

Running the Tests

Required Software

Optional Software

To run functional tests in a browser, follow the instructions in Running Tests with Selenium.

Setting Up

  1. Clone the develop branch of Mojito:

    $ git clone https://github.com/yahoo/mojito.git --branch develop
    
  2. Change to the mojito directory.

  3. Install the Mojito dependencies:

    $ npm install
    

Running Tests with PhantomJS

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.

Using npm

  1. From the mojito directory, run both the unit and functional tests with npm:

    $ npm test

  2. To run only unit tests, use the following:

    $ npm run-script unit

  3. To run only functional tests, use the following:

    $ npm run-script func

Using run.js

  1. Change to the mojito/tests directory.

  2. 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

  3. 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

Running Tests with Selenium

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.

  1. Install Selenium:

  2. Change to the mojito/tests directory.

  3. Start the Selenium server in the background:

    $ java -jar path/to/selenium-server.jar &

  4. 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

  5. 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.

  6. 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 the func directory: func/examples/newsboxes/newsboxes_descriptor.json

Test Results

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.

Unit 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
  • Use the option --reportFolder to specify the location to write test results:

    $ ./run.js test -u --path unit --browser phantomjs --reportFolder <dir>

Functional Tests

  • 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
  • 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>