-
Notifications
You must be signed in to change notification settings - Fork 2
Testing
- We automate testing
- We use a Test Driven Development (TDD) approach (but for a different perspective, read Heinemeier Hansson's commentary on TDD)
- Testing is the hard part of software development
- There are no rules about testing (including this one)
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.
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.
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:
- https://en.wikipedia.org/wiki/Acceptance_test-driven_development
- https://en.wikipedia.org/wiki/Behavior-driven_development
- https://en.wikipedia.org/wiki/Specification_by_example
The definitions of Acceptance Test Driven Development (ATDD) and Behaviour Driven Development (BDD) in the Wikipedia articles may be too strict for our purposes.
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.
But there are guidelines.
[Collaborating on Projects](Using GitHub to Collaborate on We Enhance IT Projects)