I am deeply confused the difference. I've read so many definitions and they always explain functional test as testing the requirement is satisfied. Well, that's just rephrasing the name functional test. That doesn't clarify the difference.

I am interested in some real code to demonstrate the difference.

Suppose we have a function in a library performs hashing:

def custom_hasher(scheme, val):
    # use many hashing libraries...

def hasher(inlist, scheme):
    """ Take a list and outputs the hashed values of a list. """

    output = list()
    for val in inlist:
        output.append(custom_hasher(scheme, val))
    return output

Now for a functional test, I am guessing we want to test ['a', 'b'] is returned as something like ['jask34sdasdas', 'asasjdk234sjdk'] given some scheme.

But that's just about what an integration test can do! I know exactly what type input I want (I want good execution so I pass in a list), or I want it to raise Object has no append method exception if I pass in a dictionary.

I can do that in both. Where's the distinction?

Another example is some web app:

@logged_in   # only logged in user can do this
@route("/invite", method=['POST'])
def send_invite(request):
   recp_email = request.data['recp_email']

   # now do a bunch of logics before and after sending an email

So in my integration test, I will definitely do this over a network (have the server running). Send some request to this url. Same for functional test.

How to draw a line? For this case, I can write a functional test that tests to find an email is sent by looking at the send log in some table. But that's a different function than what I am testing (the view send_invite).

So I don't see how to differentiate the two. They both assert something.

Please help.


Functional tests are generally used as a synonym for integration tests. You may be confusing the unit tests with functional tests if I understood your question correctly.

In unit tests, aim to test the function itself in isolation, by mocking/stubbing other components.

In integration tests, test different systems working together, to see if they work together correctly to produce the correct output.

For your example send_invite, in unit tests, you can mock the email and other framework components, and just test if the send invite function correctly calls the email component with correct arguments. For the integration tests, you can set up a testing server and see if the function correctly sends emails and does everything it supposed to do, including the other components.

Unit tests are the smallest testing block, followed by the integration tests.


Let's leave the words aside and approach the problem as why we need tests. We need tests to ensure our code is working correctly.

In the send_email example, first we need to test the function in isolation to see it does what it supposed to do. We do this by isolating the function from other components by mocking/stubbing to test the function itself. Assuming we have a different component that is responsible for sending emails, and our function is calling this component to send emails, if our email component is broken, we won't want this to affect the test of send_email, it's not directly related to this function. We just want to make sure the code in the send_email function is working correctly. That is generally called unit testing.

After we are sure the function is working correctly in isolation, we need to test if the invitation system is working correctly, with all of it's components. This time we do it by testing the function without mocks/stubs. This is generally called integration tests.

In some places, there are functional tests with side effects and functional tests without side effects, which means calling the function with predefined arguments in tests without mocking/stubbing to see it produces the correct output, and calling the function with predefined arguments in tests with mocking/stubbing other components, respectively. This can translates into unit tests and integration tests.

The language can be confusing, and different cultures/communities sometimes call these tests with different words. What needs to be done in testing is, starting testing with the smallest meaningful unit possible, and work from there to whole system.(This can be done in reverse order too, but it's out of the scope of this answer)

  • Thanks. You can write an integration test that tests send_invite which does not stub/mock expensive dependencies such as SMTP server. Furthermore, in the example I gave, send_invite is a view so I can write both integration test and unittest. I can supply a fake request and fake http client and runs my unittest, whereas in integration I run the real wsgi server. A functional test is not really a synonym for integration tests based on other online answers. Or I should rephrase - natural language is ambiguous. We have "system tests", "acceptance/functional tests" and mind blow :( – CppLearner Feb 10 '13 at 7:43
  • Different words can be used in different cultures for different meanings. What I learned and using is unit tests(testing the smallest block) -> 'integration tests(testing if the individually tested blocks are working together correctly) -> acceptance tests'(testing if the whole system is working correctly) – Hakan Deryal Feb 10 '13 at 7:48
  • Yes.I understand them by name and I stated that in my first few lines. But what is lacking is real code demonstration. If you actually look at send_invite example, the requirement given by your boss is "it has to send out an email", so you'd assert that statement to demonstrate "it works as required!" which counts that as functional test. But your integration test will just do about the same thing, assert something very similar to the requirement. The only difference I can make when testing send_invites is setup a local mail server and tests whether the email is received or not-> fnal test – CppLearner Feb 10 '13 at 7:57
  • Edited my answer for clarity. – Hakan Deryal Feb 10 '13 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.