Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Testing

alexanderelliott121 edited this page Jan 17, 2017 · 30 revisions

Backend Testing

The backend tests are located in bonnie/test/. Sample data used in the backend tests islocated in bonnie/test/fixtures. To execute all of the backend tests, run:

bundle exec rake

This will result in the generation of a coverage report using simplecov. The coverage report can be found in bonnie/coverage.

If you do not want to wait for the whole test suite to run, you can run individual test files by running:

rake TEST=<test/test_file_to_run>

It is important to remember to start each setup portion of new test files with 'dump_database' to ensure that any changes made to fixtures in previous tests do not hold. If you are going to add fixtures, do not add them to existing fixture sets (eg: records/base_set). Instead, create your own new set (eg: records/<your_set_name>) and place the new fixtures here.

Frontend Testing

The frontend tests are located in the models,views and integration directories found in bonnie/spec/javascripts. Sample data used in the frontend tests is located in bonnie/spec/javascripts/fixtures. These tests are written in coffeescript and make use of the jasmine testing framework. Code-coverage for the frontend tests is accomplished through the use of istanbul and teaspoon. To generate coverage reports, you will first have to install istanbul:

npm install -g istanbul

If the install command does not work, make sure you set the npm proxy variable if applicable:

npm set proxy http://yourcompanyproxy.com:8080

To run the frontend tests, you can start the rails server and navigate to 127.0.0.1:3000/teaspoon. Or alternatively to run the frontend tests and generate a coverage report, run:

rake teaspoon USE_COVERAGE=default

The generated coverage reports can be found in bonnie/coverage-frontend

###Front End Fixture/State Loading

Tests should avoid side effects by loading (likely in beforeEach ->) their fixtures using the BonnieRouterCache.

At the startup of front-end tests execution, measure fixtures for jasmine tests are automatically loaded by setup/measure.js.erb which searches the fixtures directory for all directories containing files titled measures.json. Each of these files will be loaded, along with the value_sets.json file that needs to exist with them, into an instance of BonnieRouter that will be stored.

In order load a specific state, use the command:

window.bonnieRouterCache.load(key)

where the key is the path from fixtures to the files. For example, use the command:

window.bonnieRouterCache.load('base_set')

to load the fixture bonnie/spec/javascripts/fixtures/measure_data/base_set/measures.json

###Selenium Frontend Testing In order to run Selenium using Teaspoon you will need to download and install a driver for the given browser you want to test with. Please go to the [Selenium Browsers Page] (http://www.seleniumhq.org/about/platforms.jsp#browsers) for more information.

In this example we will be downloading the Chrome driver. Download the latest driver, unpack the zip and update the PATH environment variable with the install location:

  1. Open up the terminal
  2. Run sudo vim /etc/paths
  3. Enter password
  4. Add the path to the driver to the end of the file
  5. To double check, relaunch the terminal and run "echo $PATH". You should see your newly added path.

Next, in spec/teaspoon_env.rb, uncomment the following lines:

config.driver = :selenium
config.driver_options = {client_driver :chrome}

Replace ":chrome" with the driver you want to run. Once the lines are uncommented, bundling and running "rake teaspoon" will run all tests using the chosen browser.