alchemist 0.9.0 copy "alchemist: ^0.9.0" to clipboard
alchemist: ^0.9.0 copied to clipboard

A support package that aims to make golden testing in Flutter easier and more streamlined.

example/example.md

Alchemist Example #

For a more detailed explanation on how Betterment uses Alchemist, read the included Recommended Setup Guide.

Full Example Project #

A full project containing an application containing exemplary widgets and golden tests is included in the example folder.

Basic usage #

In your project's test/ directory, add a file for your widget's tests. Then, write and run golden tests by using the goldenTest function.

We recommend putting all golden tests related to the same component into a test group.

Every goldenTest commonly contains a group of scenarios related to each other (for example, all scenarios that test the same constructor or widget in a particular context).

This example shows a basic golden test for ListTiles that makes use of some of the more advanced features of the goldenTest API to control the output of the test.

import 'package:alchemist/alchemist.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('ListTile Golden Tests', () {
    goldenTest(
      'renders correctly',
      fileName: 'list_tile',
      builder: () => GoldenTestGroup(
        scenarioConstraints: const BoxConstraints(maxWidth: 600),
        children: [
          GoldenTestScenario(
            name: 'with title',
            child: const ListTile(
              title: Text('ListTile.title'),
            ),
          ),
          GoldenTestScenario(
            name: 'with title and subtitle',
            child: const ListTile(
              title: Text('ListTile.title'),
              subtitle: Text('ListTile.subtitle'),
            ),
          ),
          GoldenTestScenario(
            name: 'with trailing icon',
            child: const ListTile(
              title: Text('ListTile.title'),
              trailing: Icon(Icons.chevron_right_rounded),
            ),
          ),
        ],
      ),
    );
  });
}

Then, simply run Flutter test and pass the --update-goldens flag to generate the golden files.

flutter test --update-goldens

gitignore #

We recommend adding the following lines to your project's .gitignore file to prevent platform-specific artifacts from being included in your git repository.

# Ignore platform-specific goldens
**/goldens/macos
**/goldens/linux
**/goldens/windows
157
likes
0
pub points
87%
popularity

Publisher

verified publisherbetterment.dev

A support package that aims to make golden testing in Flutter easier and more streamlined.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter, flutter_test, meta

More

Packages that depend on alchemist