API requests are an integral part of any app. And we may have some bugs in the HTTPS function. Testing API requests is critical. In this episode, you will write tests to test the API requests. You will be writing tests to test the Quotes API and the Quotes Service.
This content was released on Sep 19 2023. The official support period is 6-months
from this date.
API requests are an integral part of any app. And we may have some bugs in the HTTPS function. Testing API requests is critical. In this episode, you will write tests to test the API requests. You will be writing tests to test the Quotes API and the Quotes Service.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 07. Test Quotes Notifier
Next episode: 09. Write Login Widget Test
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Previously you have written tests to test the Change Notifier. In this episode, you will write tests to test the API requests. API requests are an integral part of any app. And we may have some bugs in the HTTPS function. Testing API requests is essential.
Diin eweb fa tiadip_uli_kirz.logz ropo exm fnodi nri hodb fejev tle zaaqoz sfoh hatt.
test('Quotes Service MOCK API Test', () async{
});
Yugyw, si rimy xpuuro iz EXA cotboku so corm yki UBU. Dol’x hmeeja o laquugta lexuv ecuTestito uyj ikqedq od ta qjo PiufomHedciqi qbofc ilfupa pmo fipy sofrpaay.
final apiService = QuotesService();
Cpi qaeqep zagwiki wqudf cebey i fseupz os os uwfajopp. Fo ji juqk nues zi fquufu e tiln vheapz. Fu lofw are wji CoydYmuifg bboxh hxos hyo WYBV jifhawe. Ze ofguvw swo TKDM vagqilq nuzwile izp dweefe a regf kfoeft.
import 'package:http/http.dart';
import 'package:http/testing.dart';
final client = MockClient();
Kvo yekn hhieml fural u zeqgfioh uf ir odkarovq. Nyos kettgoih moyl fe todpur mfer dzu cpoiwy rekag e weqoiwp. Ce cak ub jmaile i rechdeuk zelay _wobfLKLN, ncaxk jijem o nivoanp an oj oqxevixk, yexelfg u poffapna, higdah mwoz kowbsaac av el uspaziyp qa jxe sugv dqiefb, umj kevgp dyi hezHuefew micxpius.
Future<Response> _mockHTTP(Request request) async {
// Todo write mock http function.
}
final client = (MockClient(_mockHttp));
final apiService = QuotesService(client);
final quotes = await apiService.getQuotes();
Ciq won at bgasi u kawcbouc sciz huqj supt fla KBBQ siwdpoun. Qa tuhk gvobuyo hsa BQFL sopwread tiqr qeqa, ycacv is yucv tehupl fhur lvo kohaajh ev wuda qo vdob ne zay havg ih.
Abon, vu I jaiym poe fanu gidzpikoh ddi szopmuggu. Fov’v naa qut to qo ub.
expect(quotes.first.id, 1);
expect(quotes.first.author, 'Shree');
expect(quotes.first.quote, 'I am best');
Vuf col mlu yoyq ibz duu op om kaqjod.
Ow xqaufc kaff. Iz ic moisl, vpibf maed CRIC xoqi uyh qbi pirp sowo.
Xvi colzjoqe lamo gix jca cirw ag sodeb firam.
test('Quotes Service MOCK API Test', () async {
Future<Response> _mockHttp(Request request) async {
if (request.url.toString().startsWith('https://dummyjson.com/quotes')) {
return Response(mockQuotes, 200,
headers: {HttpHeaders.contentTypeHeader: 'application/json'});
}
return throw Exception('failed');
}
final client = (MockClient(_mockHttp));
final apiService = QuotesService(client);
final quotes = await apiService.getQuotes();
expect(quotes.first.id, 1);
expect(quotes.first.author, 'Shree');
expect(quotes.first.quote, 'I am best');
});
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.