Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

Testing

Addison Martin edited this page May 13, 2019 · 35 revisions

This section will show you how to run all the system tests, as well as how to add new tests. See the table of contents, for setting up your development environment first.

If you encounter any errors with this wiki, or the project in general, please submit a new issue!

Debugging with the Rails Console

Using the rails console, you can interact directly with the app, even when its not running.

rails console

See this link for some tips and tricks.

Running the Tests

Navigate into the project's root folder.

cd share-the-food/

Run the unit tests.

rails test

Run the system, i.e. feature, tests.

rails test:system

Static Code Analyzer

Rubocop

Navigate to the project's root folder.

cd share-the-food/

Run Rubocop, the analyzer. Also, require its performance analyzer.

rubocop --require rubocop-performance

Rubocop can automatically fix many of the issues it detects.

rubocop -a

Sonarqube

A sonarqube analysis is automatically performed by Travis CI. Visit the dashboard.

Rubycritic

Navigate to the project's root folder.

cd share-the-food/

Run the Ruby static code analyzer. The app parameter excludes test, configuration, etc. code.

rubycritic app

The results will open in a web browser.

Brakeman

Navigate to the project's root folder.

cd share-the-food/

Run the brakeman Ruby on Rails static code analyzer.

brakeman

The results will output to the terminal.

Rails Best Practices Gem

Navigate to the project's root folder.

cd share-the-food/

Run the Rails Best Practices static code analyzer.

rails_best_practices -f html .

The results will output in share-the-food/rails_best_practices_output.html

Performance Test

Fasterer

Navigate to the project's root folder.

cd share-the-food/

Run the fasterer tool. It will output any suggests to speed up Ruby code.

Bullet

In development, the Bullet gem will detect any query that could be sped up and alert the developer, through the console, pop-ups, etc.

Finding Database Indexes to Speed up Performance

Navigate to the project's root folder.

cd share-the-food/

Run the database analyzer, to find if any indexes should be added to any database columns to increase performance.

lol_dba db:find_indexes

Continuous Integration

Each commit and pull request has all tests and a style check automatically run by Travis CI. The master branch is protected, you cannot commit directly into it. Instead, create another branch, make your changes, then create a pull request into master. Only once all tests have passed (and someone else has reviewed the code) can the pull request be merged.

Adding New Tests

Tests are located in share-the-food/test.

Test data are stored in fixtures at test/fixtures. Each file is split per model.

Unit tests are located in /test/models/*. Each file is split per model.

Feature tests are located in /test/system/*. Each file is a different page of the website. Multiple features are stored per file.

Tests for controllers, helpers, mailers, and integration tests can also be added (they currently don't have any tests written) in test/controllers/, test/helpers/, test/mailers/, and test/integration/.