Minitest in Rails
Rails ships with Minitest and RubyDev embraces it for fast, batteries-included testing. The framework provides assertions, spec-style syntax, benchmarks, and parallel test execution without extra gems.
Test directories & helpers
Unit tests
`test/models`, `test/services`, `test/lib`. Require `test_helper`, leverage fixtures or factories, and assert small units of behaviour.
Integration & system
`test/integration` (request-style) and `test/system` (Capybara). Use `sign_in_as`, `visit`, and `assert_selector` helpers to simulate real flows.
Benchmarks
`test/performance` uses `Minitest::Benchmark`. Benchmark hot code paths (e.g., report generation) to prevent regressions.
Assertions and spec-style DSL
Need RSpec-like syntax? Include `require "minitest/spec"` and define `describe`/`it` blocks while still using Minitest assertions.
Harness parallelization safely
Rails runs tests in parallel by default (`parallelize(workers: :number_of_processors)`). Ensure stateful resources (files, Redis) are isolated per worker.
- Wrap global configuration in `parallelize_setup` / `parallelize_teardown` to avoid race conditions.
- Use `with_lock_retries` around database writes that might clash between workers.
- Tag brittle suites with `self.use_transactional_tests = true` to reset data instantly.
Everyday workflow
- Run focused suites with `bin/rails test test/services --seed 12345` to reproduce order-dependent failures.
- Leverage fixtures in `test/fixtures/*.yml` for canonical data; supplement with FactoryBot when relationships get complex.
- Use `assert_enqueued_with` and `assert_performed_with` for ActiveJob assertions when verifying Sidekiq jobs.
- Capture regressions via `assert_changes`/`assert_no_changes` when validating state transitions.