views:

94

answers:

2

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  A: 

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.

dss539
So in functionals, should you then test every possible contingency? It sounds like you really can't leave anything out of functionals.
fig
I don't think you test every contingency in functionals, you test the contingencies that are explicitly stated in the specification. You will likely also have unit tests for these, and hopefully some other unit tests for things you thought of and they didn't.
Robert
I am definitely *not* a testing expert. So beware of taking any advice from me, but I would at least do sanity checking of the feature required in the spec. Your unit test may brute force test all possible US zip codes, but your functional test may try 1 invalid and 1 valid zip.
dss539
+1  A: 

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.

Robert Munteanu
fig
Rule of the thumb is to cover one use case out of a 'story' with one integration test. For instance if I would have a payment page I would simply process a successful payment to validate that the integration is done right. The unit test would cover all the other cases.
Robert Munteanu