Types of tests

Tests will commonly be either a unit test that tests one thing, or an integration test that tests many things. Here's the same behavior tested in two different ways:

# Unit test example: tests the model
test 'Article publishing' do
  expect(article.published_at).to eq Time.now
# Integration test example: tests your router,
# controller, view, and model all at once
test 'Article publishing' do
  post '/articles/my-draft-article/publish'
  expect(article.published_at).to eq Time.now

In web development, unit tests are often written for models and services, while integration tests are for controllers.

Smoke tests

A smoke test is a very shallow integration test. It usually just tries something and expects no errors to happen. The name comes from testing electronics to check if turning a device on produces smoke. In web development, it usually means just visiting a path and checking for errors.

test 'No fires happen' do
  visit '/article/my-article'
  expect(response.code).to eq 200

The simple test above will already check for a lot of things:

  • Any errors in the view templates
  • Any model or controller errors
  • Middleware in the app server
See also...

Next: Why do we write tests?

results matching ""

    No results matching ""