Skip to content
pubscout

testainers

0.4.0, released 6 months ago by testainers.com

Manages containers for testing purposes in Dart and Flutter.

$ flutter pub add testainers
Source repository

What it does

Testainers is a Dart plugin that streamlines the management of containers for testing. It allows developers to programmatically spin up, configure, and tear down isolated test environments using predefined or custom containers like PostgreSQL, Redis, and MongoDB.

AI-written summary of version 0.4.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to run integration or unit tests requiring real databases or external services inside containers.
  • You want automated container lifecycle management within your Dart test suites.

Skip it when

  • You are running tests in an environment that does not support Docker or container orchestration.
  • You do not use containerized dependencies in your testing workflow.

Strengths

  • Provides predefined support for common services like PostgreSQL, Redis, and MongoDB.
  • Seamlessly integrates with the standard Dart test library for setup and teardown hooks.

Weaknesses

  • Requires a running Docker/container environment to function.
  • Limited documentation outside of basic usage examples.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
0

Requires a working Docker environment on the host machine to spin up containers during tests.

import 'dart:io';
import 'package:http/http.dart';
import 'package:test/test.dart';
import 'package:testainers/testainers.dart';

void main() {
  group('Test Httpbucket', () {
    final TestainersHttpbucket container = TestainersHttpbucket();

    setUpAll(() async {
      await container.start();
    });

    test('Http Test', () async {
      final Response response = await get(
        Uri.parse('http://localhost:${container.httpPort}/methods'),
      );

      expect(response.statusCode, 200);
    });

    tearDownAll(container.stop);
  });
}

Alternatives

Packages that do the same job and could replace testainers.

  • bloc_test

    A testing library that makes it easy to test blocs and cubits.

  • riverpod_lint

    Riverpod_lint is a static analysis plugin that flags common Riverpod mistakes and offers quick refactorings.

  • golden_test

    A zero-dependency wrapper for Flutter golden tests with theme, locale, and multi-device support.

  • elementary_test

    Testing library for apps built with the Elementary architecture.