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 3, 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:

bundle exec ruby -I 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

###Creating Frontend Fixtures From Existing Measures/Patients

There are currently two categories of frontend fixtures: those that are loaded through bonnieRouterCache and those that are loaded through jasmine.getJSONFixtures

Before creating fixtures, be aware that, by convention, record fixtures are created before any measure update actions are performed. This should be relevant in cases where measure history elements are being tested.

BonnieRouterCache fixtures are based on back-end fixtures. To generate a set: Create a measure fixture json named measures.json (The fixture export rake tasks will make this easy).

1 Create the directory structure that will contain the files to be loaded.

  • If the fixtures are intended to be loaded with the measure_history_spec_loader, three paths will be required: under draft_measure, records and upload_summaries.
  • Convention is that directories under the category should be organized feature/set purpose/base cms/state/versioned cms for measure_data and records, feature/set purpose/base cms for upload_summaries 2 Edit the measure json so that the top level of the json hierarchy is a json array. 3 In the same directory as the measures.json file, create a value_sets.json file. 4 value_sets.json should be populated by a json object mapping oids to value_sets

Pure Frontend fixtures, open the developer console on whatever browser you are using. Execute the command "window.bonnie.mainView" This should give you the javascript object containing the current view.

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