Difference between functional test and integration test

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.


EDIT:

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)

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật