Skip to content

Testing Guide

Martin Mendoza edited this page Jun 5, 2025 · 3 revisions

Testing Guide

This page explains how to run, write, and maintain tests for the StateForce project.

Types of Tests

  • Unit tests: Test individual models, services, and utility classes.
  • Integration tests: Test interactions between multiple components, such as controllers and database.
  • System/Feature tests: Simulate user interactions with the application through the UI.

Running the Test Suite

To run all tests:

bundle exec rspec

You can run a specific test file:

bundle exec rspec spec/path/to/your_spec.rb

Or run only tests matching a description:

bundle exec rspec -e "description"

Test Environment Setup

  • Ensure you have copied .env.test or set up the correct environment variables for testing.
  • The test database is separate from development and production. It will be created and migrated automatically.

To prepare the test database:

rails db:create RAILS_ENV=test
rails db:migrate RAILS_ENV=test

Writing Tests

  • Place unit and integration tests under spec/models, spec/controllers, etc.
  • Use FactoryBot for creating test data.
  • Use fixtures or test doubles for external services (e.g., Google OAuth2, Redis).
  • Follow the Rspec Rails Guide for best practices.

Code Quality

  • Run RuboCop to check for linting and style violations:
bundle exec rubocop

Continuous Integration

  • All pull requests must pass the test suite before merging.
  • Failed tests should be addressed promptly.

Troubleshooting

  • If tests are failing unexpectedly, check for missing migrations or pending schema changes.
  • Sometimes clearing the test database can help:
rails db:drop db:create db:migrate RAILS_ENV=test

Resources

πŸ“š StateForce Wiki Sidebar

Welcome to the StateForce Wiki! Use this sidebar to navigate through the documentation.


🏠 Home


πŸ›  System Design


πŸ—„ Database


🎨 Design & Style


🚦 User Workflows


πŸ§ͺ Testing


πŸ“Ž Others

This sidebar provides quick access to all the documentation pages. For detailed information, click on the desired section.

Clone this wiki locally