flutter_test library Null safety

Testing library for flutter, built on top of package:test.

Test Configuration

The testing library exposes a few constructs by which projects may configure their tests.

Per test or per file

Due to its use of package:test as a foundation, the testing library allows for tests to be initialized using the existing constructs found in package:test. These include the setUp and setUpAll methods.

Per directory hierarchy

In addition to the constructs provided by package:test, this library supports the configuration of tests at the directory level.

Before a test file is executed, the Flutter test framework will scan up the directory hierarchy, starting from the directory in which the test file resides, looking for a file named flutter_test_config.dart. If it finds such a configuration file, the file will be assumed to have a main method with the following signature:

Future<void> testExecutable(FutureOr<void> Function() testMain);

The test framework will execute that method and pass it the main() method of the test. It is then the responsibility of the configuration file's main() method to invoke the test's main() method.

After the test framework finds a configuration file, it will stop scanning the directory hierarchy. In other words, the test configuration file that lives closest to the test file will be selected, and all other test configuration files will be ignored. Likewise, it will stop scanning the directory hierarchy when it finds a pubspec.yaml, since that signals the root of the project.

If no configuration file is located, the test will be executed like normal.

See also:

Classes

AccessibilityGuideline
An accessibility guideline describes a recommendation an application should meet to be considered accessible.
AnimationSheetBuilder
Records the frames of an animating widget, and later displays the frames as a grid in an animation sheet.
AutomatedTestWidgetsFlutterBinding
A variant of TestWidgetsFlutterBinding for executing tests in the flutter test environment.
ChainedFinder
Applies additional filtering against a parent Finder.
CommonFinders
Provides lightweight syntax for getting frequently used widget Finders.
ComparisonResult
The result of a pixel comparison test.
CustomMatcher
A useful utility class for implementing other matchers through inheritance. Derived classes should call the base constructor with a feature name and description, and an instance matcher, and should implement the featureValueOf abstract method.
CustomMinimumContrastGuideline
A guideline which verifies that all elements specified by finder meet minimum contrast levels.
DefaultTestVariant
The TestVariant that represents the "default" test that is run if no variants iterable is specified for testWidgets.
DefaultWebGoldenComparator
An unsupported WebGoldenComparator that exists for API compatibility.
Description
Matchers build up their error messages by appending to Description objects.
Evaluation
The result of evaluating a semantics node by a AccessibilityGuideline.
Fake
A stand-in for another object which cannot be used except for specifically overridden methods.
FakeAccessibilityFeatures
Test version of AccessibilityFeatures in which specific features may be set to arbitrary values.
Finder
Searches a widget tree and returns nodes that match a particular pattern.
FrameTimingSummarizer
This class and summarizes a list of FrameTiming for the performance metrics.
Future<T>
The result of an asynchronous computation.
GoldenFileComparator
Compares image pixels against a golden image file.
KeyEventSimulator
A class that serves as a namespace for a bunch of keyboard-key generation utilities.
KeySimulatorTransitModeVariant
A TestVariant that runs tests with transit modes set to different values of KeyDataTransitMode.
LabeledTapTargetGuideline
A guideline which enforces that all nodes with a tap or long press action also have a label.
LiveTestWidgetsFlutterBinding
A variant of TestWidgetsFlutterBinding for executing tests in the flutter run environment, on a device. This is intended to allow interactive test development.
LiveWidgetController
Variant of WidgetController that can be used in tests running on a device.
LocalFileComparator
The default GoldenFileComparator implementation for flutter test.
Matcher
The base class for all matchers.
MatchFinder
Searches a widget tree and returns nodes that match a particular pattern.
MinimumTapTargetGuideline
A guideline which enforces that all tappable semantics nodes have a minimum size.
MinimumTextContrastGuideline
A guideline which verifies that all nodes that contribute semantics via text meet minimum contrast levels.
Offset
An immutable 2D floating-point offset.
OnPlatform
An annotation for platform-specific customizations for a test suite.
PointerEventRecord
A record of input PointerEvent list with the timeStamp of when it is injected.
Retry
An annotation for marking a test suite to be retried.
SemanticsHandle
A reference to the semantics tree.
Skip
An annotation for marking a test suite as skipped.
StreamMatcher
A matcher that matches events from Streams or StreamQueues.
StringDescription
The default implementation of Description. This should rarely need substitution, although conceivably it is a place where other languages could be supported.
Tags
An annotation for applying a set of user-defined tags to a test suite.
TargetPlatformVariant
A TestVariant that runs tests with debugDefaultTargetPlatformOverride set to different values of TargetPlatform.
TestAsyncUtils
Utility class for all the async APIs in the flutter_test library.
TestDefaultBinaryMessenger
A BinaryMessenger subclass that is used as the default binary messenger under testing environment.
TestGesture
A class for performing gestures in tests.
TestOn
An annotation indicating which platforms a test suite supports.
TestPlatformDispatcher
PlatformDispatcher that wraps another PlatformDispatcher and allows faking of some properties for testing purposes.
TestPointer
A class for generating coherent artificial pointer events.
TestRestorationData
Restoration data that can be used to restore the state to the one described by this data.
TestRestorationManager
The RestorationManager used for tests.
TestTextInput
A testing stub for the system's onscreen keyboard.
TestVariant<T>
An abstract base class for describing test environment variants.
TestViewConfiguration
A ViewConfiguration that pretends the display is of a particular size. The size is in logical pixels. The resulting ViewConfiguration maps the given size onto the actual display using the BoxFit.contain algorithm.
TestVSync
A TickerProvider that creates a standalone ticker.
TestWidgetsFlutterBinding
Base class for bindings used by widgets library tests.
TestWindow
SingletonFlutterWindow that wraps another SingletonFlutterWindow and allows faking of some properties for testing purposes.
TextEditingValue
The current text, selection, and composing state for editing a run of text.
Throws
Use the throwsA function instead.
Timeout
A class representing a modification to the default timeout for a test.
TrivialComparator
Placeholder comparator that is set as the value of goldenFileComparator when the initialization that happens in the test bootstrap either has not yet happened or has been bypassed.
TypeMatcher<T>
A Matcher subclass that supports validating the Type of the target object.
ValueVariant<T>
A TestVariant that runs separate tests with each of the given values.
WebGoldenComparator
Compares image pixels against a golden image file.
WidgetController
Class that programmatically interacts with widgets.
WidgetTester
Class that programmatically interacts with widgets and the test environment.

Mixins

LocalComparisonOutput
A mixin for use in golden file comparators that run locally and provide output.
TestDefaultBinaryMessengerBinding
Overrides the ServicesBinding's binary messenger logic to use TestDefaultBinaryMessenger.

Extensions

TestBasicMessageChannelExtension
Shim to support the obsolete setMockMessageHandler and checkMockMessageHandler methods on BasicMessageChannel in tests.
TestBinaryMessengerExtension
Shim to support the obsolete setMockMessageHandler and checkMockMessageHandler methods on BinaryMessenger in tests.
TestMethodChannelExtension
Shim to support the obsolete setMockMethodCallHandler and checkMockMethodCallHandler methods on MethodChannel in tests.

Constants

androidTapTargetGuideline → const AccessibilityGuideline
A guideline which requires tappable semantic nodes a minimum size of 48 by 48.
MinimumTapTargetGuideline(size: Size(48.0, 48.0), link: 'https://support.google.com/accessibility/android/answer/7101858?hl=en')
anything → const Matcher
A matcher that matches any value.
_IsAnything()
clipsWithBoundingRect → const Matcher
Asserts that a Finder locates a single object whose root RenderObject is a RenderClipRect with no clipper set, or an equivalent RenderClipPath.
_ClipsWithBoundingRect()
find → const CommonFinders
Some frequently used widget Finders.
CommonFinders._()
findsNothing → const Matcher
Asserts that the Finder matches no widgets in the widget tree.
_FindsWidgetMatcher(null, 0)
findsOneWidget → const Matcher
Asserts that the Finder locates at exactly one widget in the widget tree.
_FindsWidgetMatcher(1, 1)
findsWidgets → const Matcher
Asserts that the Finder locates at least one widget in the widget tree.
_FindsWidgetMatcher(1, null)
hasAGoodToStringDeep → const Matcher
Asserts that an object's toStringDeep() is a plausible multiline description.
_HasGoodToStringDeep()
hasNoImmediateClip → const Matcher
Asserts that a Finder locates a single object whose root RenderObject is not a RenderClipRect, RenderClipRRect, RenderClipOval, or RenderClipPath.
_MatchAnythingExceptClip()
hasOneLineDescription → const Matcher
Asserts that an object's toString() is a plausible one-line description.
_HasOneLineDescription()
iOSTapTargetGuideline → const AccessibilityGuideline
A guideline which requires tappable semantic nodes a minimum size of 44 by 44.
MinimumTapTargetGuideline(size: Size(44.0, 44.0), link: 'https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/'…
isArgumentError → const TypeMatcher<ArgumentError>
A matcher for ArgumentError.
TypeMatcher<ArgumentError>()
isBrowser → const bool
Whether the test is running in a web browser compiled to JavaScript.
identical(0, 0.0)
isCastError → const TypeMatcher<CastError>
A matcher for CastError.
@Deprecated('CastError has been deprecated in favor of TypeError. ' 'Use `isA<TypeError>()` or, if you need compatibility with older SDKs, ' 'use `isA<CastError>()` and ignore the deprecation.')
TypeMatcher<CastError>()
isConcurrentModificationError → const TypeMatcher<ConcurrentModificationError>
A matcher for ConcurrentModificationError.
TypeMatcher<ConcurrentModificationError>()
isCyclicInitializationError → const TypeMatcher<CyclicInitializationError>
A matcher for CyclicInitializationError.
TypeMatcher<CyclicInitializationError>()
isEmpty → const Matcher
Returns a matcher that matches the isEmpty property.
_Empty()
isException → const TypeMatcher<Exception>
A matcher for Exception.
TypeMatcher<Exception>()
isFalse → const Matcher
A matcher that matches anything except the Boolean value true.
_IsFalse()
isFormatException → const TypeMatcher<FormatException>
A matcher for FormatException.
TypeMatcher<FormatException>()
isInCard → const Matcher
Asserts that the Finder locates a single widget that has at least one Card widget ancestor.
_IsInCard()
isList → const TypeMatcher<List>
A matcher for List.
TypeMatcher<List>()
isMap → const TypeMatcher<Map>
A matcher for Map.
TypeMatcher<Map>()
isNaN → const Matcher
A matcher that matches the numeric value NaN.
_IsNaN()
isNegative → const Matcher
A matcher which matches if the match argument is negative.
_OrderingMatcher(0, false, true, false, 'a negative value', false)
isNonNegative → const Matcher
A matcher which matches if the match argument is zero or positive.
_OrderingMatcher(0, true, false, true, 'a non-negative value', false)
isNonPositive → const Matcher
A matcher which matches if the match argument is zero or negative.
_OrderingMatcher(0, true, true, false, 'a non-positive value', false)
isNonZero → const Matcher
A matcher which matches if the match argument is non-zero.
_OrderingMatcher(0, false, true, true, 'a value not equal to')
isNoSuchMethodError → const TypeMatcher<NoSuchMethodError>
A matcher for NoSuchMethodError.
TypeMatcher<NoSuchMethodError>()
isNotEmpty → const Matcher
Returns a matcher that matches the isNotEmpty property.
_NotEmpty()
isNotInCard → const Matcher
Asserts that the Finder locates a single widget that has no Card widget ancestors.
_IsNotInCard()
isNotNaN → const Matcher
A matcher that matches any non-NaN value.
_IsNotNaN()
isNotNull → const Matcher
A matcher that matches any non-null value.
_IsNotNull()
isNull → const Matcher
A matcher that matches any null value.
_IsNull()
isNullThrownError → const TypeMatcher<NullThrownError>
A matcher for NullThrownError.
TypeMatcher<NullThrownError>()
isOffstage → const Matcher
Asserts that the Finder locates a single widget that has at least one Offstage widget ancestor.
_IsOffstage()
isOnstage → const Matcher
Asserts that the Finder locates a single widget that has no Offstage widget ancestors.
_IsOnstage()
isPositive → const Matcher
A matcher which matches if the match argument is positive.
_OrderingMatcher(0, false, false, true, 'a positive value', false)
isRangeError → const TypeMatcher<RangeError>
A matcher for RangeError.
TypeMatcher<RangeError>()
isStateError → const TypeMatcher<StateError>
A matcher for StateError.
TypeMatcher<StateError>()
isTrue → const Matcher
A matcher that matches the Boolean value true.
_IsTrue()
isUnimplementedError → const TypeMatcher<UnimplementedError>
A matcher for UnimplementedError.
TypeMatcher<UnimplementedError>()
isUnsupportedError → const TypeMatcher<UnsupportedError>
A matcher for UnsupportedError.
TypeMatcher<UnsupportedError>()
isZero → const Matcher
A matcher which matches if the match argument is zero.
_OrderingMatcher(0, true, false, false, 'a value equal to')
kDebugWarning → const String
The warning message to show when a benchmark is performed with assert on.
''' ┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓ ┇ ⚠ THIS BENCHMARK IS BEING RUN IN DEBUG MODE ⚠ ┇ ┡╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┦ │ …
kDragSlopDefault → const double
The default drag touch slop used to break up a large drag into multiple smaller moves.
20.0
labeledTapTargetGuideline → const AccessibilityGuideline
A guideline which enforces that all nodes with a tap or long press action also have a label.
LabeledTapTargetGuideline._()
returnsNormally → const Matcher
A matcher that matches a function call against no exception.
_ReturnsNormally()
textContrastGuideline → const AccessibilityGuideline
A guideline which requires text contrast to meet minimum values.
throws → const Matcher
This function is deprecated.
@Deprecated('Will be removed in 0.13.0')
Throws()
throwsArgumentError → const Matcher
A matcher for functions that throw ArgumentError.
Throws(isArgumentError)
throwsConcurrentModificationError → const Matcher
A matcher for functions that throw ConcurrentModificationError.
Throws(isConcurrentModificationError)
throwsCyclicInitializationError → const Matcher
A matcher for functions that throw CyclicInitializationError.
Throws(isCyclicInitializationError)
throwsException → const Matcher
A matcher for functions that throw Exception.
Throws(isException)
throwsFormatException → const Matcher
A matcher for functions that throw FormatException.
Throws(isFormatException)
throwsNoSuchMethodError → const Matcher
A matcher for functions that throw NoSuchMethodError.
Throws(isNoSuchMethodError)
throwsNullThrownError → const Matcher
A matcher for functions that throw NullThrownError.
Throws(isNullThrownError)
throwsRangeError → const Matcher
A matcher for functions that throw RangeError.
Throws(isRangeError)
throwsStateError → const Matcher
A matcher for functions that throw StateError.
Throws(isStateError)
throwsUnimplementedError → const Matcher
A matcher for functions that throw Exception.
Throws(isUnimplementedError)
throwsUnsupportedError → const Matcher
A matcher for functions that throw UnsupportedError.
Throws(isUnsupportedError)

Properties

autoUpdateGoldenFiles bool
Whether golden files should be automatically updated during tests rather than compared to the image bytes recorded by the tests.
read / write
completes Matcher
Matches a Future that completes successfully with any value.
final
doesNotComplete Matcher
Matches a Future that does not complete.
final
emitsDone StreamMatcher
Returns a StreamMatcher that asserts that the stream emits a "done" event.
final
goldenFileComparator GoldenFileComparator
Compares pixels against those of a golden image file.
read / write
isAssertionError TypeMatcher<AssertionError>
A matcher for AssertionError.
final
isFlutterError TypeMatcher<FlutterError>
A matcher for FlutterError.
final
isLinux bool
Whether the test is running on the Linux operating system.
read-only
isMacOS bool
Whether the test is running on the macOS operating system.
read-only
isWindows bool
Whether the test is running on the Windows operating system.
read-only
kBuildBudget Duration
The maximum amount of time considered safe to spend for a frame's build phase. Anything past that is in the danger of missing the frame as 60FPS.
read / write
neverCalled Null Function([Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?, Object?])
Returns a function that causes the test to fail if it's called.
read-only
reportTestException TestExceptionReporter
A function that is called by the test framework when an unexpected error occurred during a test.
read / write
throwsAssertionError Matcher
A matcher for functions that throw AssertionError.
final
throwsFlutterError Matcher
A matcher for functions that throw FlutterError.
final
webGoldenComparator WebGoldenComparator
Compares pixels against those of a golden image file.
read / write

Functions

addStateInfo(Map matchState, Map values) → void
Useful utility for nesting match states.
addTearDown(dynamic callback()) → void
Registers a function to be run after the current test.
allOf(Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) Matcher
This returns a matcher that matches if all of the matchers passed as arguments (up to 7) match.
anyElement(Object? valueOrMatcher) Matcher
Returns a matcher which matches Iterables in which at least one element matches the given valueOrMatcher.
anyOf(Object? arg0, [Object? arg1, Object? arg2, Object? arg3, Object? arg4, Object? arg5, Object? arg6]) Matcher
Matches if any of the given matchers evaluate to true.
benchmarkWidgets(WidgetTesterCallback callback, {bool mayRunWithAsserts = false, bool semanticsEnabled = false}) Future<void>
Runs the callback inside the Flutter benchmark environment.
clipsWithBoundingRRect({required BorderRadius borderRadius}) Matcher
Asserts that a Finder locates a single object whose root RenderObject is a RenderClipRRect with no clipper set, and border radius equals to borderRadius, or an equivalent RenderClipPath.
clipsWithShapeBorder({required ShapeBorder shape}) Matcher
Asserts that a Finder locates a single object whose root RenderObject is a RenderClipPath with a ShapeBorderClipper that clips to shape.
closeTo(num value, num delta) Matcher
Returns a matcher which matches if the match argument is within delta of some value.
collapseWhitespace(String string) String
Utility function to collapse whitespace runs to single spaces and strip leading/trailing whitespace.
collectAllElementsFrom(Element rootElement, {required bool skipOffstage}) Iterable<Element>
Provides an iterable that efficiently returns all the elements rooted at the given element. See CachingIterable for details.
compareLists(List<int>? test, List<int>? master) Future<ComparisonResult>
Returns a ComparisonResult to describe the pixel differential of the test and master image bytes provided.
completion(dynamic matcher, [String? description]) Matcher
Matches a Future that completes successfully with a value that matches matcher.
contains(Object? expected) Matcher
Returns a matcher that matches if the match argument contains the expected value.
containsAll(Iterable expected) Matcher
Matches Iterables which contain an element matching every value in expected in any order, and may contain additional values.
containsAllInOrder(Iterable expected) Matcher
Matches Iterables which contain an element matching every value in expected in the same order, but may contain additional values interleaved throughout.
containsPair(Object? key, Object? valueOrMatcher) Matcher
Returns a matcher which matches maps containing the key-value pair with key => valueOrMatcher.
containsValue(Object? value) Matcher
Returns a matcher which matches maps containing the given value.
coversSameAreaAs(Path expectedPath, {required Rect areaToCompare, int sampleSize = 20}) Matcher
Asserts that 2 paths cover the same area by sampling multiple points.
createTestImage({int width = 1, int height = 1, bool cache = true}) Future<Image>
Creates an arbitrarily sized image for testing.
doesNotMeetGuideline(AccessibilityGuideline guideline) → AsyncMatcher
The inverse matcher of meetsGuideline.
emits(dynamic matcher) StreamMatcher
Returns a StreamMatcher for matcher.
emitsAnyOf(Iterable matchers) StreamMatcher
Returns a StreamMatcher that matches the stream if at least one of matchers matches.
emitsError(dynamic matcher) StreamMatcher
Returns a StreamMatcher that matches a single error event that matches matcher.
emitsInAnyOrder(Iterable matchers) StreamMatcher
Returns a StreamMatcher that matches the stream if each matcher in matchers matches, in any order.
emitsInOrder(Iterable matchers) StreamMatcher
Returns a StreamMatcher that matches the stream if each matcher in matchers matches, one after another.
emitsThrough(dynamic matcher) StreamMatcher
Returns a StreamMatcher that matches any number of events followed by events that match matcher.
endsWith(String suffixString) Matcher
Returns a matcher that matches if the match argument is a string and ends with suffixString.
equals(Object? expected, [int limit = 100]) Matcher
Returns a matcher that matches if the value is structurally equal to expected.
equalsIgnoringCase(String value) Matcher
Returns a matcher which matches if the match argument is a string and is equal to value when compared case-insensitively.
equalsIgnoringHashCodes(String value) Matcher
Asserts that two Strings are equal after normalizing likely hash codes.
equalsIgnoringWhitespace(String value) Matcher
Returns a matcher which matches if the match argument is a string and is equal to value, ignoring whitespace.
escape(String str) String
Returns str with all whitespace characters represented as their escape sequences.
everyElement(Object? valueOrMatcher) Matcher
Returns a matcher which matches Iterables in which all elements match the given valueOrMatcher.
expect(dynamic actual, dynamic matcher, {String? reason, dynamic skip}) → void
Assert that actual matches matcher.
expectAsync(Function callback, {int count = 1, int max = 0, String? id, String? reason}) Function
This function is deprecated because it doesn't work well with strong mode. Use expectAsync0, expectAsync1, expectAsync2, expectAsync3, expectAsync4, expectAsync5, or expectAsync6 instead.
@Deprecated('Will be removed in 0.13.0')
expectAsync0<T>(T callback(), {int count = 1, int max = 0, String? id, String? reason}) Func0<T>
Informs the framework that the given callback of arity 0 is expected to be called count number of times (by default 1).
expectAsync1<T, A>(T callback(A), {int count = 1, int max = 0, String? id, String? reason}) Func1<T, A>
Informs the framework that the given callback of arity 1 is expected to be called count number of times (by default 1).
expectAsync2<T, A, B>(T callback(A, B), {int count = 1, int max = 0, String? id, String? reason}) Func2<T, A, B>
Informs the framework that the given callback of arity 2 is expected to be called count number of times (by default 1).
expectAsync3<T, A, B, C>(T callback(A, B, C), {int count = 1, int max = 0, String? id, String? reason}) Func3<T, A, B, C>
Informs the framework that the given callback of arity 3 is expected to be called count number of times (by default 1).
expectAsync4<T, A, B, C, D>(T callback(A, B, C, D), {int count = 1, int max = 0, String? id, String? reason}) Func4<T, A, B, C, D>
Informs the framework that the given callback of arity 4 is expected to be called count number of times (by default 1).
expectAsync5<T, A, B, C, D, E>(T callback(A, B, C, D, E), {int count = 1, int max = 0, String? id, String? reason}) Func5<T, A, B, C, D, E>
Informs the framework that the given callback of arity 5 is expected to be called count number of times (by default 1).
expectAsync6<T, A, B, C, D, E, F>(T callback(A, B, C, D, E, F), {int count = 1, int max = 0, String? id, String? reason}) Func6<T, A, B, C, D, E, F>
Informs the framework that the given callback of arity 6 is expected to be called count number of times (by default 1).
expectAsyncUntil0<T>(T callback(), bool isDone(), {String? id, String? reason}) Func0<T>
Informs the framework that the given callback of arity 0 is expected to be called until isDone returns true.
expectAsyncUntil1<T, A>(T callback(A), bool isDone(), {String? id, String? reason}) Func1<T, A>
Informs the framework that the given callback of arity 1 is expected to be called until isDone returns true.
expectAsyncUntil2<T, A, B>(T callback(A, B), bool isDone(), {String? id, String? reason}) Func2<T, A, B>
Informs the framework that the given callback of arity 2 is expected to be called until isDone returns true.
expectAsyncUntil3<T, A, B, C>(T callback(A, B, C), bool isDone(), {String? id, String? reason}) Func3<T, A, B, C>
Informs the framework that the given callback of arity 3 is expected to be called until isDone returns true.
expectAsyncUntil4<T, A, B, C, D>(T callback(A, B, C, D), bool isDone(), {String? id, String? reason}) Func4<T, A, B, C, D>
Informs the framework that the given callback of arity 4 is expected to be called until isDone returns true.
expectAsyncUntil5<T, A, B, C, D, E>(T callback(A, B, C, D, E), bool isDone(), {String? id, String? reason}) Func5<T, A, B, C, D, E>
Informs the framework that the given callback of arity 5 is expected to be called until isDone returns true.
expectAsyncUntil6<T, A, B, C, D, E, F>(T callback(A, B, C, D, E, F), bool isDone(), {String? id, String? reason}) Func6<T, A, B, C, D, E, F>
Informs the framework that the given callback of arity 6 is expected to be called until isDone returns true.
expectLater(dynamic actual, dynamic matcher, {String? reason, dynamic skip}) Future<void>
Just like expect, but returns a Future that completes when the matcher has finished matching.
expectSync(dynamic actual, dynamic matcher, {String? reason}) → void
Assert that actual matches matcher.
fail(String message) → Never
Convenience method for throwing a new TestFailure with the provided message.
findsAtLeastNWidgets(int n) Matcher
Asserts that the Finder locates at least a number of widgets in the widget tree.
findsNWidgets(int n) Matcher
Asserts that the Finder locates the specified number of widgets in the widget tree.
greaterThan(Object value) Matcher
Returns a matcher which matches if the match argument is greater than the given value.
greaterThanOrEqualTo(Object value) Matcher
Returns a matcher which matches if the match argument is greater than or equal to the given value.
group(Object description, void body(), {dynamic skip}) → void
Creates a group of tests.
hasLength(Object? matcher) Matcher
Returns a matcher that matches if an object has a length property that matches matcher.
inClosedOpenRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than or equal to a low and less than high.
inExclusiveRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than low and less than high.
inInclusiveRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than or equal to low and less than or equal to high.
inOpenClosedRange(num low, num high) Matcher
Returns a matcher which matches if the match argument is greater than low and less than or equal to high.
isA<T>() TypeMatcher<T>
Returns a matcher that matches objects with type T.
isIn(Object? expected) Matcher
Returns a matcher that matches if the match argument is in the expected value. This is the converse of contains.
isInstanceOf<T>() TypeMatcher<T>
A matcher that compares the type of the actual value to the type argument T.
isMethodCall(String name, {required dynamic arguments}) Matcher
A matcher for MethodCalls, asserting that it has the specified method name and arguments.
isNot(Object? valueOrMatcher) Matcher
Returns a matcher that inverts valueOrMatcher to its logical negation.
isSameColorAs(Color color) Matcher
Asserts that the object represents the same color as color when used to paint.
lessThan(Object value) Matcher
Returns a matcher which matches if the match argument is less than the given value.
lessThanOrEqualTo(Object value) Matcher
Returns a matcher which matches if the match argument is less than or equal to the given value.
markTestSkipped(String message) → void
Marks the current test as skipped.
matches(Pattern re) Matcher
Returns a matcher that matches if the match argument is a string and matches the regular expression given by re.
matchesGoldenFile(Object key, {int? version}) → AsyncMatcher
Asserts that a Finder, Future<ui.Image>, or ui.Image matches the golden image file identified by key, with an optional version number.
matchesReferenceImage(Image image) → AsyncMatcher
Asserts that a Finder, Future<ui.Image>, or ui.Image matches a reference image identified by image.
matchesSemantics({String? label, AttributedString? attributedLabel, String? hint, AttributedString? attributedHint, String? value, AttributedString? attributedValue, String? increasedValue, AttributedString? attributedIncreasedValue, String? decreasedValue, String? tooltip, AttributedString? attributedDecreasedValue, TextDirection? textDirection, Rect? rect, Size? size, double? elevation, double? thickness, int? platformViewId, int? maxValueLength, int? currentValueLength, bool hasCheckedState = false, bool isChecked = false, bool isSelected = false, bool isButton = false, bool isSlider = false, bool isKeyboardKey = false, bool isLink = false, bool isFocused = false, bool isFocusable = false, bool isTextField = false, bool isReadOnly = false, bool hasEnabledState = false, bool isEnabled = false, bool isInMutuallyExclusiveGroup = false, bool isHeader = false, bool isObscured = false, bool isMultiline = false, bool namesRoute = false, bool scopesRoute = false, bool isHidden = false, bool isImage = false, bool isLiveRegion = false, bool hasToggledState = false, bool isToggled = false, bool hasImplicitScrolling = false, bool hasTapAction = false, bool hasLongPressAction = false, bool hasScrollLeftAction = false, bool hasScrollRightAction = false, bool hasScrollUpAction = false, bool hasScrollDownAction = false, bool hasIncreaseAction = false, bool hasDecreaseAction = false, bool hasShowOnScreenAction = false, bool hasMoveCursorForwardByCharacterAction = false, bool hasMoveCursorBackwardByCharacterAction = false, bool hasMoveCursorForwardByWordAction = false, bool hasMoveCursorBackwardByWordAction = false, bool hasSetTextAction = false, bool hasSetSelectionAction = false, bool hasCopyAction = false, bool hasCutAction = false, bool hasPasteAction = false, bool hasDidGainAccessibilityFocusAction = false, bool hasDidLoseAccessibilityFocusAction = false, bool hasDismissAction = false, String? onTapHint, String? onLongPressHint, List<CustomSemanticsAction>? customActions, List<Matcher>? children}) Matcher
Asserts that a SemanticsNode contains the specified information.
mayEmit(dynamic matcher) StreamMatcher
Returns a StreamMatcher that allows (but doesn't require) matcher to match the stream.
mayEmitMultiple(dynamic matcher) StreamMatcher
Returns a StreamMatcher that matches any number of events that match matcher.
meetsGuideline(AccessibilityGuideline guideline) → AsyncMatcher
Asserts that the currently rendered widget meets the provided accessibility guideline.
moreOrLessEquals(double value, {double epsilon = precisionErrorTolerance}) Matcher
Asserts that two doubles are equal, within some tolerated error.
neverEmits(dynamic matcher) StreamMatcher
Returns a StreamMatcher that matches a stream that never matches matcher.
nonconst<T>(T t) → T
This function can be used to call a const constructor in such a way as to create a new instance rather than creating the common const instance.
offsetMoreOrLessEquals(Offset value, {double epsilon = precisionErrorTolerance}) Matcher
Asserts that two Offsets are equal, within some tolerated error.
orderedEquals(Iterable expected) Matcher
Returns a matcher which matches Iterables that have the same length and the same elements as expected, in the same order.
pairwiseCompare<S, T>(Iterable<S> expected, bool comparator(S, T), String description) Matcher
A pairwise matcher for Iterables.
predicate<T>(bool f(T), [String description = 'satisfies function']) Matcher
Returns a matcher that uses an arbitrary function that returns true or false for the actual value.
printOnFailure(String message) → void
Prints message if and when the current test fails.
prints(dynamic matcher) Matcher
Matches a Function that prints text that matches matcher.
pumpEventQueue({int times = 20}) Future
Returns a Future that completes after the event loop has run the given number of times (20 by default).
rectMoreOrLessEquals(Rect value, {double epsilon = precisionErrorTolerance}) Matcher
Asserts that two Rects are equal, within some tolerated error.
registerException(Object error, [StackTrace stackTrace = StackTrace.empty]) → void
Registers an exception that was caught for the current test.
rendersOnPhysicalModel({BoxShape? shape, BorderRadius? borderRadius, double? elevation}) Matcher
Asserts that a Finder locates a single object whose root RenderObject is a RenderPhysicalModel or a RenderPhysicalShape.
rendersOnPhysicalShape({required ShapeBorder shape, double? elevation}) Matcher
Asserts that a Finder locates a single object whose root RenderObject is RenderPhysicalShape that uses a ShapeBorderClipper that clips to shape as its clipper. If elevation is non null asserts that RenderPhysicalShape.elevation is equal to elevation.
reportExpectCall(StackTrace stack, List<DiagnosticsNode> information) int
Report call site for expect() call. Returns the number of frames that should be elided if a stack were to be modified to hide the expect call, or zero if no such call was found.
same(Object? expected) Matcher
Returns a matches that matches if the value is the same instance as expected, using identical.
setUp(dynamic body()) → void
Registers a function to be run before tests.
setUpAll(dynamic body()) → void
Registers a function to be run once before all tests.
simulateKeyDownEvent(LogicalKeyboardKey key, {String? platform, PhysicalKeyboardKey? physicalKey, String? character}) Future<bool>
Simulates sending a hardware key down event through the system channel.
simulateKeyRepeatEvent(LogicalKeyboardKey key, {String? platform, PhysicalKeyboardKey? physicalKey, String? character}) Future<bool>
Simulates sending a hardware key repeat event through the system channel.
simulateKeyUpEvent(LogicalKeyboardKey key, {String? platform, PhysicalKeyboardKey? physicalKey}) Future<bool>
Simulates sending a hardware key up event through the system channel.
spawnHybridCode(String dartCode, {Object? message, bool stayAlive = false}) StreamChannel
Spawns a VM isolate that runs the given dartCode, which is loaded as the contents of a Dart library.
spawnHybridUri(dynamic uri, {Object? message, bool stayAlive = false}) StreamChannel
Spawns a VM isolate for the given uri, which may be a Uri or a String.
startsWith(String prefixString) Matcher
Returns a matcher that matches if the match argument is a string and starts with prefixString.
stringContainsInOrder(List<String> substrings) Matcher
Returns a matcher that matches if the match argument is a string and contains a given list of substrings in relative order.
tearDown(dynamic body()) → void
Registers a function to be run after tests.
tearDownAll(dynamic body()) → void
Registers a function to be run once after all tests.
test(Object description, dynamic body(), {String? testOn, Timeout? timeout, dynamic skip, dynamic tags, Map<String, dynamic>? onPlatform, int? retry}) → void
Creates a new test case with the given description (converted to a string) and body.
testWidgets(String description, WidgetTesterCallback callback, {bool? skip, Timeout? timeout, Duration? initialTimeout, bool semanticsEnabled = true, TestVariant<Object?> variant = const DefaultTestVariant(), dynamic tags}) → void
Runs the callback inside the Flutter test environment.
throwsA(dynamic matcher) Matcher
This can be used to match three kinds of objects:
unorderedEquals(Iterable expected) Matcher
Returns a matcher which matches Iterables that have the same length and the same elements as expected, but not necessarily in the same order.
unorderedMatches(Iterable expected) Matcher
Returns a matcher which matches Iterables whose elements match the matchers in expected, but not necessarily in the same order.
within<T>({required num distance, required T from, DistanceFunction<T>? distanceFunction}) Matcher
Asserts that two values are within a certain distance from each other.
wrapMatcher(Object? valueOrMatcher) Matcher
Takes an argument and returns an equivalent Matcher.

Enums

EnginePhase
Phases that can be reached by WidgetTester.pumpWidget and TestWidgetsFlutterBinding.pump.
LiveTestWidgetsFlutterBindingFramePolicy
Available policies for how a LiveTestWidgetsFlutterBinding should paint frames.
TestBindingEventSource
Parts of the system that can generate pointer events that reach the test binding.
TextInputAction
An action the user has requested the text input control to perform.

Typedefs

AllMessagesHandler = Future<ByteData?>? Function(String channel, MessageHandler? handler, ByteData? message)
A function which takes the name of the method channel, it's handler, platform message and asynchronously returns an encoded response.
AnyDistanceFunction = num Function(Never a, Never b)
The type of a union of instances of DistanceFunction<T> for various types T.
DistanceFunction<T> = num Function(T a, T b)
Computes the distance between two values.
ElementPredicate = bool Function(Element element)
Signature for CommonFinders.byElementPredicate.
ErrorFormatter = String Function(dynamic actual, Matcher matcher, String? reason, Map matchState, bool verbose)
The type used for functions that can be used to build up error reports upon failures in expect.
@Deprecated('Will be removed in 0.13.0.')
EventDispatcher = Future<void> Function(PointerEvent event)
Signature for a callback that can dispatch events and returns a future that completes when the event dispatch is complete.
Func0<T> = T Function()
Func1<T, A> = T Function([A a])
Func2<T, A, B> = T Function([A a, B b])
Func3<T, A, B, C> = T Function([A a, B b, C c])
Func4<T, A, B, C, D> = T Function([A a, B b, C c, D d])
Func5<T, A, B, C, D, E> = T Function([A a, B b, C c, D d, E e])
Func6<T, A, B, C, D, E, F> = T Function([A a, B b, C c, D d, E e, F f])
HitTester = HitTestResult Function(Offset location)
Signature for callbacks that perform hit-testing at a given location.
TestExceptionReporter = void Function(FlutterErrorDetails details, String testDescription)
Signature for the reportTestException callback.
WidgetPredicate = bool Function(Widget widget)
Signature for CommonFinders.byWidgetPredicate.
WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester)
Signature for callback to testWidgets and benchmarkWidgets.

Exceptions / Errors

TestFailure
An exception thrown when a test assertion fails.