Skip to content

Testing

Larry Reid edited this page Aug 23, 2017 · 2 revisions

TL;DR

Test Driven Development

Write tests for a new feature, and run it before writing the code for the feature, so you can see that the test fails. It's easy to write a test that passes even when the code isn't working. By watching the test fail, it's less likely that the test is wrong.

If the test is for a bug that's been discovered, same story. Write the test before fixing the bug. This has the added benefit of requiring that the conditions that lead to the bug are well enough understood to write test cases.

Unit Testing

TDD probably started with unit testing, and TDD is easiest to conceptualize in the unit testing space. Typically unit tests are simple, small test cases that test relatively small, isolated pieces of code.

We follow the Rails standard for unit testing, using the MiniTest library that comes out of the box with Rails. When testing plain old Ruby objects (POROs), we put the tests in the test/models directory.

Acceptance Testing

I'm using "acceptance testing" to mean a test from the perspective of the end user. Typically, that means it's expressed as actions on the user interface and the results of those actions, (often, but not always) expressed as those results visible to an end user.

We see Rails 5.1 system testing as where we do acceptance testing.

Some links:

The definitions of Acceptance Test Driven Development (ATDD) and Behaviour Driven Development (BDD) in the Wikipedia articles may be too strict for our purposes.

Controller Testing

With Rails 5, controller testing (or "functional testing" in a lot of Rails documentation) has fallen out of favour. Some of the code that supported controller testing has even been deprecated or moved to gems that aren't installed by default (e.g. the assigns method that used to allow you to see the models that the controller had modified).

Read Heinemeier Hansson's reasons for the change in the Github issue.

There are no Rules

But there are guidelines.

Home

[Collaborating on Projects](Using GitHub to Collaborate on We Enhance IT Projects)

Clone this wiki locally