flame_test library

Classes

DebugTextRenderer
Text formatter suitable for use in golden tests. This formatter renders words as rectangles.
FlameTester<T extends FlameGame<World>>
Customize this class with your specific FlameGame type T and a custom provider () -> T, plus some additional configurations including a game widget builder createGameWidget, a custom pumpWidget function and a custom gameSize.
GameTester<T extends Game>
Customize this class with your specific Game type T and a custom provider () -> T, plus some additional configurations including a game widget builder createGameWidget, a custom pumpWidget function and a custom gameSize.

Extensions

FlameFinds on CommonFinders
FlameGameExtension on Component

Properties

flameGame FlameTester<FlameGame<World>>
Default instance of Flame Tester to be used when you don't care about changing any configuration.
final

Functions

closeToAabb(Aabb2 expected, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if the argument is an axis-aligned bounding box sufficiently close (within distance epsilon) to expected. Example of usage:
closeToMatrix4(Matrix4 matrix, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if each entry in a 4x4 matrix is within a distance epsilon of the corresponding entry in matrix.
closeToQuaternion(Quaternion quaternion, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if the argument is a Quaternion within distance epsilon of quaternion. For example:
closeToVector(Vector2 vector, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if the argument is a vector within distance epsilon of vector. For example:
closeToVector3(Vector3 vector, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if the argument is a 3d vector within distance epsilon of vector. For example:
closeToVector4(Vector4 vector, [double epsilon = 1e-15]) Matcher
Returns a matcher which checks if the argument is a 4d vector within distance epsilon of vector. For example:
createDragStartEvents({required Game game, int? pointerId, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → DragStartEvent
createDragUpdateEvents({required Game game, int? pointerId, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → DragUpdateEvent
createMouseMoveEvent({required Game game, int? pointerId, Vector2? position, Vector2? delta, Duration? timestamp}) → PointerMoveEvent
createSecondaryTapDownEvents({required Game game, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → SecondaryTapDownEvent
createSecondaryTapUpEvents({required Game game, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → SecondaryTapUpEvent
createTapDownEvents({required Game game, int? pointerId, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → TapDownEvent
createTapUpDetails({Offset? globalPosition, Offset? localPosition, PointerDeviceKind kind = PointerDeviceKind.mouse}) TapUpDetails
createTapUpEvents({required Game game, int? pointerId, PointerDeviceKind? kind, Offset? globalPosition, Offset? localPosition}) → TapUpEvent
expectColor(Color actual, Color expected, {String? reason, double delta = 0.0000001}) → void
A test helper function that compares two Color objects for equality with floating-point tolerance.
expectColorAlpha(Color actual, Color expected, {String? reason, double delta = 0.0000001}) → void
A test helper function that compares only the alpha component of two Color objects with floating-point tolerance.
expectDouble(double d1, double d2, {double epsilon = 0.01, String? reason}) → void
failsAssert([String? message]) Matcher
Matcher that can be used in a test that expects an assertion error.
generateImage([int width = 1, int height = 1]) Future<Image>
generatePNGByteData() ByteData
initializeFlameGame() Future<FlameGame<World>>
initializeGame<T extends FlameGame<World>>(CreateFunction<T> create) Future<T>
nextFloat32(double value) double
Returns the next larger representable float32 value from value.
prevFloat32(double value) double
Returns the next smaller representable float32 value from value.
seedFromEnvironment(int? seed) int?
Get the random seed for a test. If the seed parameter is passed in, it takes precedence. Otherwise, if the environment variable RANDOM_SEED is set, it is used. If neither is set, returns null. Note: When using this, the random_test_test will fail because it will use the same seed for all tests. This is expected.
testGolden(String testName, PrepareFunction testBody, {required String goldenFile, Vector2? size, Color? backgroundColor, FlameGame<World>? game, bool skip = false}) → void
Test that a game renders correctly.
testRandom(String name, void body(Random random), {int? seed, String? testOn, Timeout? timeout, dynamic skip, dynamic tags, Map<String, dynamic>? onPlatform, int? retry, int repeatCount = 1}) → void
This function is equivalent to test(name, body), except that it is better suited for randomized testing: it will create a Random generator and pass it to the test body, but also record the seed that was used for creating the random generator. Thus, if a test fails for a specific rare seed, it would be easy to reproduce this failure.
testWidgetsRandom(String description, TestWidgetsCallback callback, {int? seed, bool? skip, Timeout? timeout, bool semanticsEnabled = true, dynamic tags}) → void
This function is equivalent to testWidgets(name, body), except that it is better suited for randomized testing: it will create a Random generator and pass it to the test body, but also record the seed that was used for creating the random generator. Thus, if a test fails for a specific rare seed, it would be easy to reproduce this failure.
testWithFlameGame(String testName, AsyncGameFunction<FlameGame<World>> testBody, {Timeout? timeout, dynamic tags, dynamic skip, Map<String, dynamic>? onPlatform, int? retry}) Future<void>
Utility function for writing tests that require a FlameGame instance.
testWithGame<T extends FlameGame<World>>(String testName, CreateFunction<T> create, AsyncGameFunction<T> testBody, {Timeout? timeout, dynamic tags, dynamic skip, Map<String, dynamic>? onPlatform, int? retry}) Future<void>
Utility function for writing tests that require a custom game instance.
toleranceFloat32(double value) double
Calculate the tolerance for tests of float32 value that use double precision. This is a wrapper for calling nextFloat32 - prevFloat32 for value.
toleranceVector2Float32(Vector2 value) double
Calculate the float32 tolerance for the Vector2 value that uses double precision. This is a wrapper for calling sum(toleranceFloat32) for each element.

Typedefs

AsyncGameFunction<T extends Game> = Future<void> Function(T game)
AsyncVoidFunction = Future<void> Function()
CreateFunction<T> = T Function()
GameCreateFunction<T extends Game> = T Function()
GameWidgetCreateFunction<T extends Game> = GameWidget<T> Function(T game)
PumpWidgetFunction<T extends Game> = Future<void> Function(GameWidget<T>, WidgetTester tester)
TestWidgetsCallback = Future<void> Function(Random random, WidgetTester widgetTester)
VerifyFunction<T extends Game> = dynamic Function(T)
WidgetSetupFunction<T extends Game> = Future<void> Function(T, WidgetTester)
WidgetVerifyFunction<T extends Game> = Future<void> Function(T, WidgetTester)