-
Notifications
You must be signed in to change notification settings - Fork 27
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.
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
When writing jasmine tests that require the loading of JSONFixtures through the use of the jasmine-jquery getJSONFixture function, it is important call 'jasmine.getJSONFixtures().clearCache()' first which ensures that getJSONFixture will not return fixtures modified by the running of previous tests/specs.
###Front End Fixture/State Loading
Tests that require calculations/calculation should load their fixtures using the BonnieRouterCache Measure fixtures for jasmine tests are automatically loaded when the tests are executed: setup/measure.js.erb 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, the command
window.bonnieRouterCache.load($key)
Where the key is the path from fixtures to the files. Ex. To load the fixtures from the directory "bonnie/spec/javascripts/fixtures/base_set/measures.json", the command would be
window.bonnieRouterCache.load("base_set)
###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:
- Open up the terminal
- Run sudo vim /etc/paths
- Enter password
- Add the path to the driver to the end of the file
- 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.