http_client_test 0.1.0 copy "http_client_test: ^0.1.0" to clipboard
http_client_test: ^0.1.0 copied to clipboard

Test HTTP clients using a snapshot of the request and response

This package provides an easy way to write tests for API clients communicating over HTTP (REST, GraphQL, ...).

Usage #

import 'package:test/test.dart';
import 'package:http_client_test/http_client_test.dart';

void main() {
  group('UserClient', () {
    test('getById', () async {
      // fails when the request sent doesn't match the specified request.
      // The return value of the send function will be returned.
      final result = await matchesRequestSnapshot(
        // invoke the client with the provided server endpoint.
        send: (endpoint) => UserClient(endpoint).getById(12),
        // file path containing a snapshot of the expected request.
        request: 'user_client_test.request.http',
        // (optional) file path containing a snapshot of the simulated response.
        response: 'user_client_test.response.http',
      );

      // return value of the client can be tested against the simulated response.
      expect(result.id, equals(12));
      expect(result.name, equals('Bob'));
    });
  });
}
2
likes
150
pub points
7%
popularity

Publisher

verified publishersoftwarefreak.net

Test HTTP clients using a snapshot of the request and response

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection

More

Packages that depend on http_client_test