Skip to main content
Version: v3.0

Testing

Backend

Rhino uses minitest for all testing on the backend. The tests are located in the test directory. By default the tests will run with parallel workers. Set the PARALLEL_WORKERS environment variable to 1 to run the tests in serial.

Read more on testing in Rails.

Running tests

All tests can be run with the following command:

rails test

run a single test file:

rails test test/models/user_test.rb

run a single test (:5 indicates the line number the test starts on)

rails test test/models/user_test.rb:5

Debugging tests

The debugger gem is included in Rhino. To use it, add the following to your test:

require "test_helper"

class CurrencyTest < ActiveSupport::TestCase
test "currency should be created" do
debugger
assert Currency.new(name: "currency", code: "code").valid?
end
end

Then run the tests with the following command so that they do not run in parallel:

PARALLEL_WORKERS=1 rails test test/models/user_test.rb

Test Data

Rhino can use built-in Rails fixtures and also provides FactoryBot in combination with FFaker for generating test data. FactoryBot is configured to use the test/factories directory.

tip

Often models require unique data for attributes. FFaker provides a unique method to ensure that the data is unique. FFaker::Name.unique.name

Mock third-party APIs

The webmock gem is included in Rhino. To use it, and mock third-party APIs add the following to your test:

require "test_helper"
require "webmock/minitest"

class CurrencyTest < ActiveSupport::TestCase
test "currency should be created" do
stub_request(:get, "https://api.example.com/customer-id/")
.to_return(status: 200, body: { id: 1 }.to_json, headers: {})
uri = URI("https://api.example.com/customer-id/")
response = Net::HTTP.get_response(uri)
data = JSON.parse(response.body)
assert_equal data["id"], 1
end
end

Read more on webmock docs.

Frontend

Unit and Component Testing

Rhino uses Vitest and React Testing Library for unit and component testing on the frontend. Background on this philosophy is here:

The tests are located in the app/frontend/__tests__ directory.

Running tests

All tests can be run with the following command:

npm test

E2E Testing

Rhino uses Cypress for E2E testing. The tests are located in the cypress/integration directory. Cypress can be loaded with the following command:

npm run cypress:open

or all tests can be executed on the command line with:

npm run cypress:run

Recording CI Runs

Cypress can be configured to record runs on Cypress Cloud. To do this, set the CYPRESS_RECORD_KEY and CYPRESS_PROJECT_ID environment variables in CircleCI -> Environment Variables -> Project Settings.