betamax 1.1.0 copy "betamax: ^1.1.0" to clipboard
betamax: ^1.1.0 copied to clipboard

outdated

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. Like Ruby's VCR gem!

Betamax #

betamax Pub test

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

✨Featuring: #

  • Recording and playback of arbitrary HTTP interactions sequences
  • Naming of fixtures based on the names of your tests, and their groups
  • Automatic test failure (in playback mode) when expected requests do not arrive
  • Support for the entire set of http's request types — basic, streamed, and multipart
  • HTTP proxy support while in record mode, via findProxyFromEnvironment
  • Easy set up!

Inspired by Ruby's VCR gem.

Getting started #

Latest Release #

dependencies:
  betamax: ^1.0.0

Example #

import 'package:betamax/betamax.dart';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';

void main() async {
  setUpAll(() {
    // We use an environment variable to determine whether we should be
    // recording or playing back HTTP interactions.
    final recordFixtures = bool.fromEnvironment('RECORD_HTTP_FIXTURES');

    Betamax.configureSuite(
      // The name of the test suite (I generally name this according to file)
      suiteName: 'echo',
      // Whether to record HTTP traffic passing through Betamax clients, or
      // to playback existing fixtures
      mode: recordFixtures ? Mode.recording : Mode.playback,
      // Path relative to `/test` where your fixtures should be stored
      relativeCassettePath: 'http_fixtures',
    );
  });

  late http.Client httpClient;
  setUp(() {
    // Sets up a new client according to the options provided to
    // `configureSuite`.
    httpClient = Betamax.clientForTest();
  });

  // Writes/reads a cassette (http fixture) to
  // `/test/http_fixtures/echo/response_is_ok.json`
  test('response is OK', () async {
    final response =
        await httpClient.get(Uri.parse('http://scooterlabs.com/echo?foo=bar'));
    expect(response.statusCode, 200);
  });
}
7
likes
0
points
87
downloads

Publisher

verified publishermadewithfelt.com

Weekly Downloads

Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. Like Ruby's VCR gem!

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, lints, meta, nock, path, slugify_string, stack_trace, test, test_api

More

Packages that depend on betamax