Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Patrick Montalto
Patrick Montalto
7,868 Points

Difference between test methods: integration, features, etc?

What is the difference between minitest and rspec, specs, features, integration tests, and so on? I'm looking for a comprehensive definition of this terminology because I'm kind of confused. Are integration tests specific to minitest? Do you only use minitest OR rspec, or do people use both in one project? I sometimes see tests like

require "test_helper"

class CanAccessHomeTest < Capybara::Rails::TestCase
  def test_homepage_has_content
    visit root_path
    assert page.has_content?("Home#index")
  end
end

but then I also see tests such as

require "test_helper"

feature "Can Access Home" do
  scenario "has content" do
    visit root_path
    page.must_have_content "Home#index"
  end
end

and

require "test_helper"

describe "Can Access Home", :capybara do
  it "has content" do
    visit root_path
    page.must_have_content "Home#index"
  end
end

Why do some use "feature" and some "describe" ? Is this terminology specific to certain kinds of tests?

1 Answer

The different syntax is for different testing frameworks. For example, the rspec syntax often uses the describe wording. You can check out one of my favorite sites for Rspec style guides at http://betterspecs.org/.

In terms of general testing, we have three main types of tests (that I can think of off the top of my head.)

  1. Integration Tests: These are the tests you use to test user behavior. Which means testing the moving parts of web application. For example, one of your example test uses capybara which can be used to emulate what a user might do while also making sure that general features are on the page when you visit them.
  2. Unit Tests: Like they sound, these tests are meant to test one thing and one thing only. They are to ensure that individual methods are properly functioning.
  3. Regression Tests: These tests are to ensure that once new features are introduced, the previous features aren't breaking. It's all fun and games with the awesome new feature until it crashes everything you've had before.

I can also do more in depth if you want. :D