77API testing, similar to unit testing, is a type of software testing that involves testing the application programming
88interface (API) directly to ensure it meets requirements for functionality, reliability, performance, and security.
99The core difference from the unit testing we have been implementing until now is that instead of testing the individual
10- functions, we are testing the entire API as a whole. API testing is therefore a form of
11- [ integration testing] ( https://en.wikipedia.org/wiki/Integration_testing ) . Additionally, another difference is that we
12- need to simulate API calls that should be as similar as possible to the ones that will be made by the users of the API.
10+ functions, we are testing the entire API as a whole.
11+
12+ !!! note "API testing vs integration testing"
13+
14+ While API testing can sometimes be a form of [integration testing](https://en.wikipedia.org/wiki/Integration_testing),
15+ it is not always the case. Integration testing specifically tests how multiple components or services work together,
16+ such as testing that your API correctly integrates with a database, external APIs, or other services. However, for
17+ the simple inference APIs we typically build in this course (load model → convert input → run inference → return
18+ output), we are not really integrating with other services. Therefore, the kind of testing we do in this module
19+ is better described as **functional testing** (testing that individual API endpoints work correctly and return the
20+ expected outputs for given inputs) and **load/performance testing** (testing how the API handles many concurrent
21+ requests) rather than integration testing.
1322
1423There are in general two things that we want to test when working with APIs:
1524
@@ -37,7 +46,7 @@ my_project
3746| |-- unittests/
3847| | |-- test_train.py
3948| | |-- test_data.py
40- | |-- integrationtests /
49+ | |-- apitests /
4150| | |-- test_apis.py
4251```
4352
@@ -63,7 +72,7 @@ to change.
6372
64732 . If you have already done the module on [ unittesting] ( ../s5_continuous_integration/unittesting.md ) then you should
6574 already have a ` tests/ ` folder. If not then create one. Inside the ` tests/ ` folder create a new folder called
66- ` integrationtests /` . Inside the ` integrationtests /` folder create a file called ` test_apis.py ` and write the
75+ ` apitests /` . Inside the ` apitests /` folder create a file called ` test_apis.py ` and write the
6776 following code:
6877
6978 ``` python
@@ -105,8 +114,8 @@ to change.
1051144 . To run the tests, you can use the following command:
106115
107116 ```bash
108- pytest tests/ integrationtests / test_apis.py
109- ```
117+ pytest tests/ apitests / test_apis.py
118+ ffffffff ```
110119
111120 Make sure that all your tests pass .
112121
0 commit comments