-
Notifications
You must be signed in to change notification settings - Fork 113
Automatic Unit Test Implementation for Network Calls
Abdul Malik edited this page Sep 3, 2022
·
2 revisions
The implementation as well as the file structure for the tests will be similar to the guidelines of the stacked architecture. For more info on testing guidelines click here.
To stub network calls we will create an extension class to the MockIOClient
in the mock_ioclient.data
file and override the post()
and get()
calls of this class. This will enable us to return the required test data response since we are not making actual network calls.
Once we override these functions we can use a simple switch statement to return the correct data depending upon the call arguments.
- Add the hardcoded data of the body that is sent (incase of a POST call) and the response from API in the
test_data.dart
file. - In the
mock_ioclient.dart
file, make sure the POST/GET call from the function returns the data from Step 1 using appropriate checks. - Add the test in the
api_service_test.dart
file
A ruTorrent-based client build in Flutter