T
T
tarp202022-02-05 01:05:22
Python
tarp20, 2022-02-05 01:05:22

unittest in python

there is a function:

def is_car_exist(make, model):
    
    url = f'https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMake/\
    {make.capitalize()}?format=json'
    data = requests.get(url).json()['Results']
    return any(model.capitalize() == car['Model_Name'] for car in data)


and an integration test to it:
class TestCar(unittest.TestCase):
    def test_is_car_exist(self):
        self.assertTrue(car.is_car_exist('honda', 'civic'))
        self.assertFalse(car.is_car_exist('Mars', 'merana'))

How to make a Unittest for this function and how does an integration test differ from a unit test?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-02-05
@Vindicar

The above code is the unit test.
A unit test verifies that a particular module (class, function, etc.) implements the expected behavior, both externally observable and internally implemented. In other words, it checks that the module conforms to the expected interface.
An integration test checks the ability of different modules to interact within the intended framework, i.e. checks the design of the interaction interface itself. Are there enough opportunities for interaction? Have we forgotten some method?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question