alchemist library

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

Classes

AlchemistConfig
A configuration object that contains settings used by Alchemist for customizing the behavior of all golden tests.
BlockedTextCanvasAdapter
An adapter used to change how a canvas draws text
BlockedTextPaintingContext
A painting context used to replace all text blocks with colored rectangles.
CiGoldensConfig
{@template ci_goldens_config} The configuration for golden tests intended to be run in CI.
GoldensConfig
{@template goldens_config} The configuration for golden tests.
GoldenTestGroup
A widget responsible for grouping test scenarios for use in golden tests.
GoldenTestScenario
A widget that displays its child with a label for use in golden tests.
HostPlatform
A class that represents a host platform that can run golden tests.
PlatformGoldensConfig
{@template platform_goldens_config} The configuration for human readable golden tests.
TestAssetBundle
An AssetBundle class used in golden testing.

Constants

defaultGoldenTestRunner → const FlutterGoldenTestRunner
Default golden test runner which uses the flutter test framework.

Properties

defaultHostPlatform HostPlatform
Default host platform (the current host machine platform).
final
goldenTestRunner ↔ GoldenTestRunner
Golden test runner. Overriding this makes it easier to unit-test Alchemist.
getter/setter pair
hostPlatform HostPlatform
Indicates the current host platform used by Alchemist. Can be overridden for testing. This value is utilized by HostPlatform.current.
getter/setter pair
pumpOnce PumpAction
A custom PumpAction that pumps the widget tree once before golden evaluation.
final

Functions

goldenTest(String description, {required String fileName, bool skip = false, List<String> tags = const ['golden'], double textScaleFactor = 1.0, BoxConstraints constraints = const BoxConstraints(), PumpAction pumpBeforeTest = onlyPumpAndSettle, PumpWidget pumpWidget = onlyPumpWidget, Interaction? whilePerforming, required ValueGetter<Widget> builder}) Future<void>
Performs a Flutter widget test that compares against golden image.
loadFonts() Future<void>
Loads a font for use in golden tests.
longPress(Finder finder) Interaction
Long-presses all widgets matching finder.
onlyPumpAndSettle(WidgetTester tester) Future<void>
A custom PumpAction that pumps and settles the widget tree before golden evaluation.
onlyPumpWidget(WidgetTester tester, Widget widget) Future<void>
A custom PumpWidget that pumps the widget tree before golden evaluation, analogous to WidgetTester.pumpWidget.
precacheImages(WidgetTester tester) Future<void>
A custom PumpAction to ensure that the images for all Image, FadeInImage, and DecoratedBox widgets are loaded before the golden file is generated.
press(Finder finder, {Duration? holdFor = const Duration(milliseconds: 300)}) Interaction
Presses all widgets matching finder.
pumpNTimes(int n, [Duration? duration]) PumpAction
Returns a custom PumpAction that pumps the widget tree n times before golden evaluation.
scroll(Finder finder, {required Offset offset, double speed = kMinFlingVelocity}) Interaction
Scrolls all widgets matching finder.

Typedefs

ColumnWidthBuilder = TableColumnWidth? Function(int columns)
A function that receives the index of a column in a table and returns the desired column width behavior.
FilePathResolver = FutureOr<String> Function(String fileName, String environmentName)
A function that returns the path of a golden test file for a given test's fileName. This function's return value should include the .png extension.
Interaction = Future<AsyncCallback?> Function(WidgetTester)
An interaction to perform while rendering a golden test. Returns an asynchronous callback that should be called to cleanup when the golden test completes.
PumpAction = Future<void> Function(WidgetTester tester)
A function that may perform pumping actions to prime a golden test.
PumpWidget = Future<void> Function(WidgetTester tester, Widget widget)
A function used to render a given Widget.