Determining whether a test is a test or an integration test

So, I'm trying to decide how to plan and organize a test suite for my python project, but I doubt when the unit test is no longer a unit test, and I would like to get some feedback from the community.

If I understand correctly:

  • A Unit test check the smallest part of your code, be it a function / method that does one and only one simple thing, even if it has several use cases.
  • The Integration test verifies that two or more units of code are executed in the same context, environment, etc. (but try to keep it at the minimum number of units per integration test), work well together and not only on their own.

I doubt that I have a simple function that executes an HTTP request and returns the contents of such a request, be it HTML, JSON, etc., it does not matter, the fact is that the function is very, very simple, but it requests information from an external source, for example:

import requests

def my_function(arg):
    # do something very simple with `arg`, like removing spaces or the simplest thing you can imagine
    return requests.get('http://www.google.com/' + arg).content

Now this is a very stupid example, but I doubt it:

Given that this function requests information from an external source when you write a test for it, can you still read such a Unit test ?

. my_function() , /db/filesystem/etc, . , , , .

!:)

P.S.: , , 100% Unit Integration, , , , , , .

+4
3

:

my_function() /db/filesystem/etc, . , , , .

, , Unit Test. Unit Test, , , .

:

, , , - a Unit test?

, , , , . , .

100% , 100% , .

, , google.com.

google.com , google (.. 100%). , google (.. 100%).

+1

, , . , unit.

, , , . mocking .

, unit.

, , my_function().

0

, , , unit test . , ( ) , sin (x). , (x), .

? - , - . , , ( ) .

, , , . ( , , , ).

, , :

  • .
  • ,
  • ,
  • ...

, , , .

0
source

Source: https://habr.com/ru/post/1541700/


All Articles