9
votes

I'm struggling to figure out what should be excluded from functional tests (in my case, using Rails, but I guess the framework's probably irrelevant).

I'm under the impression that I shouldn't bother using functional tests for things that will be caught in unit tests -- such as checking that a field can't have too many characters, or that a field can't be empty. If this is the case, what contingencies should definitely be tested with functional tests, and/or what's the rule of thumb for leaving others only for unit testing?

Or is this impression incorrect to begin with?

I've looked at this and this but I'm still at a loss.

2

2 Answers

7
votes

Functional Test: Does it do the things marketing/usability/customers signed off for? i.e. if your spec states specifically that the ZIP text box only allows valid US zip codes, then you should probably test that in a functional test.

Unit Test: Does it do what the developer expects it to do? In these tests you should use test doubles to isolate the code from dependencies.

So yes, there will be overlap of a sort.

4
votes

I for one would 'spike' through the functionality with functional tests and not worry about covering everything and instead focus in the unit tests.

Reasons:

  • functional tests are slow
  • functional tests are difficult to write and maintain
  • functional tests can only catch two extra items besides your unit tests:
    • GUI bugs
    • cross-layer mismatches

All in all, I have found that it does not pay off to cover everything twice.