Search code examples
unit-testingfunctional-testing

Confusion: leave out functional tests that cover same ground as unit tests?


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.


Solution

  • 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.