Testing library for flutter, built on top of package:test
.
Constants
- anything → Matcher
-
A matcher that matches any value.
const _IsAnything()
- findsNothing → Matcher
-
Asserts that the Finder matches no widgets in the widget tree.
const _FindsWidgetMatcher(null, 0)
- findsOneWidget → Matcher
-
Asserts that the Finder locates at exactly one widget in the widget tree.
const _FindsWidgetMatcher(1, 1)
- findsWidgets → Matcher
-
Asserts that the Finder locates at least one widget in the widget tree.
const _FindsWidgetMatcher(1, null)
- hasOneLineDescription → Matcher
-
Asserts that an object's toString() is a plausible one-line description.
const _HasOneLineDescription()
- isArgumentError → Matcher
-
A matcher for ArgumentErrors.
const _ArgumentError()
- isConcurrentModificationError → Matcher
-
A matcher for ConcurrentModificationError.
const _ConcurrentModificationError()
- isCyclicInitializationError → Matcher
-
A matcher for CyclicInitializationError.
const _CyclicInitializationError()
- isEmpty → Matcher
-
Returns a matcher that matches the isEmpty property.
const _Empty()
- isException → Matcher
-
A matcher for Exceptions.
const _Exception()
- isFalse → Matcher
-
A matcher that matches anything except the Boolean value true.
const _IsFalse()
- isFormatException → Matcher
-
A matcher for FormatExceptions.
const _FormatException()
- isInCard → Matcher
-
Asserts that the Finder locates the a single widget that has at least one Card widget ancestor.
const _IsInCard()
- isList → Matcher
-
A matcher for List types.
const _IsList()
- isMap → Matcher
-
A matcher for Map types.
const _IsMap()
- isNaN → Matcher
-
A matcher that matches the numeric value NaN.
const _IsNaN()
- isNegative → Matcher
-
A matcher which matches if the match argument is negative.
const _OrderingComparison(0, false, true, false, 'a negative value', false)
- isNonNegative → Matcher
-
A matcher which matches if the match argument is zero or positive.
const _OrderingComparison(0, true, false, true, 'a non-negative value', false)
- isNonPositive → Matcher
-
A matcher which matches if the match argument is zero or negative.
const _OrderingComparison(0, true, true, false, 'a non-positive value', false)
- isNonZero → Matcher
-
A matcher which matches if the match argument is non-zero.
const _OrderingComparison(0, false, true, true, 'a value not equal to')
- isNoSuchMethodError → Matcher
-
A matcher for NoSuchMethodErrors.
const _NoSuchMethodError()
- isNotEmpty → Matcher
-
Returns a matcher that matches the isNotEmpty property.
const _NotEmpty()
- isNotInCard → Matcher
-
Asserts that the Finder locates the a single widget that has no Card widget ancestors.
const _IsNotInCard()
- isNotNaN → Matcher
-
A matcher that matches any non-NaN value.
const _IsNotNaN()
- isNotNull → Matcher
-
A matcher that matches any non-null value.
const _IsNotNull()
- isNull → Matcher
-
A matcher that matches any null value.
const _IsNull()
- isNullThrownError → Matcher
-
A matcher for NullThrownError.
const _NullThrownError()
- isOffstage → Matcher
-
Asserts that the Finder locates the a single widget that has at least one Offstage widget ancestor.
const _IsOffstage()
- isOnstage → Matcher
-
Asserts that the Finder locates the a single widget that has no Offstage widget ancestors.
const _IsOnstage()
- isPositive → Matcher
-
A matcher which matches if the match argument is positive.
const _OrderingComparison(0, false, false, true, 'a positive value', false)
- isRangeError → Matcher
-
A matcher for RangeErrors.
const _RangeError()
- isStateError → Matcher
-
A matcher for StateErrors.
const _StateError()
- isTrue → Matcher
-
A matcher that matches the Boolean value true.
const _IsTrue()
- isUnimplementedError → Matcher
-
A matcher for UnimplementedErrors.
const _UnimplementedError()
- isUnsupportedError → Matcher
-
A matcher for UnsupportedError.
const _UnsupportedError()
- isZero → Matcher
-
A matcher which matches if the match argument is zero.
const _OrderingComparison(0, true, false, false, 'a value equal to')
- returnsNormally → Matcher
-
A matcher that matches a function call against no exception.
const _ReturnsNormally()
- throws → Matcher
-
This can be used to match two kinds of objects:
const Throws()
- throwsArgumentError → Matcher
-
A matcher for functions that throw ArgumentError.
const Throws(isArgumentError)
- throwsConcurrentModificationError → Matcher
-
A matcher for functions that throw ConcurrentModificationError.
const Throws(isConcurrentModificationError)
- throwsCyclicInitializationError → Matcher
-
A matcher for functions that throw CyclicInitializationError.
const Throws(isCyclicInitializationError)
- throwsException → Matcher
-
A matcher for functions that throw Exception.
const Throws(isException)
- throwsFormatException → Matcher
-
A matcher for functions that throw FormatException.
const Throws(isFormatException)
- throwsNoSuchMethodError → Matcher
-
A matcher for functions that throw NoSuchMethodError.
const Throws(isNoSuchMethodError)
- throwsNullThrownError → Matcher
-
A matcher for functions that throw NullThrownError.
const Throws(isNullThrownError)
- throwsRangeError → Matcher
-
A matcher for functions that throw RangeError.
const Throws(isRangeError)
- throwsStateError → Matcher
-
A matcher for functions that throw StateError.
const Throws(isStateError)
- throwsUnimplementedError → Matcher
-
A matcher for functions that throw Exception.
const Throws(isUnimplementedError)
- throwsUnsupportedError → Matcher
-
A matcher for functions that throw UnsupportedError.
const Throws(isUnsupportedError)
Typedefs
-
ElementPredicate(
Element element) → bool -
Signature for
CommonFinders.byElement
. -
ErrorFormatter(
actual, Matcher matcher, String reason, Map matchState, bool verbose) → String -
The type used for functions that can be used to build up error reports upon failures in
expect
. -
EventDispatcher(
PointerEvent event, HitTestResult result) → Future<Null> -
Signature for a callback that can dispatch events and returns a future that completes when the event dispatch is complete.
-
HitTester(
Point location) → HitTestResult -
Signature for callbacks that perform hit-testing at a given location.
-
WidgetPredicate(
Widget widget) → bool -
Signature for
CommonFinders.byPredicate
. -
WidgetTesterCallback(
WidgetTester widgetTester) → Future<Null> -
Signature for callback to testWidgets and benchmarkWidgets.
Properties
Functions
-
addStateInfo(
Map matchState, Map values) → void -
Useful utility for nesting match states.
-
allOf(
arg0, [ arg1, arg2, arg3, arg4, arg5, arg6 ]) → Matcher -
This returns a matcher that matches if all of the matchers passed as arguments (up to 7) match.
-
anyElement(
matcher) → Matcher -
Returns a matcher which matches Iterables in which at least one element matches the given
matcher
. -
anyOf(
arg0, [ arg1, arg2, arg3, arg4, arg5, arg6 ]) → Matcher -
Matches if any of the given matchers evaluate to true.
-
benchmarkWidgets(
WidgetTesterCallback callback) → Future<Null> -
Runs the
callback
inside the Flutter benchmark environment. -
closeTo(
num value, num delta) → Matcher -
Returns a matcher which matches if the match argument is within
delta
of somevalue
. -
collapseWhitespace(
String string) → String -
Utility function to collapse whitespace runs to single spaces and strip leading/trailing whitespace.
-
collectAllElementsFrom(
Element rootElement, { bool skipOffstage }) → Iterable<Element> -
Provides an iterable that efficiently returns all the elements rooted at the given element. See CachingIterable for details.
-
completion(
matcher, [ String description ]) → Matcher -
Matches a Future that completes succesfully with a value that matches
matcher
. -
contains(
expected) → Matcher -
Returns a matcher that matches if the match argument contains the expected value.
-
containsPair(
key, value) → Matcher -
Returns a matcher which matches maps containing the key-value pair with
key
=>value
. -
containsValue(
value) → Matcher -
Returns a matcher which matches maps containing the given
value
. -
endsWith(
String suffixString) → Matcher -
Returns a matcher that matches if the match argument is a string and ends with
suffixString
. -
equals(
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. -
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(
matcher) → Matcher -
Returns a matcher which matches Iterables in which all elements match the given
matcher
. -
expect(
actual, matcher, { String reason, bool verbose: false, formatter }) → void -
Assert that
actual
matchesmatcher
. -
expectAsync(
Function callback, { int count: 1, int max: 0, String id, String reason }) → Function -
Indicate that
callback
is expected to be calledcount
number of times (by default 1). -
expectAsyncUntil(
Function callback, bool isDone(), { String id, String reason }) → Function -
Indicate that
callback
is expected to be called untilisDone
returns true. -
expectSync(
actual, matcher, { String reason, bool verbose: false, formatter }) → void -
Assert that
actual
matchesmatcher
. -
fail(
String message) → void -
Convenience method for throwing a new TestFailure with the provided
message
. -
findsNWidgets(
int n) → Matcher -
Asserts that the Finder locates the specified number of widgets in the widget tree.
-
greaterThan(
value) → Matcher -
Returns a matcher which matches if the match argument is greater than the given
value
. -
greaterThanOrEqualTo(
value) → Matcher -
Returns a matcher which matches if the match argument is greater than or equal to the given
value
. -
group(
description, dynamic body(), { String testOn, Timeout timeout, skip, tags, Map<String, dynamic> onPlatform }) → void -
Creates a group of tests.
-
hasLength(
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 thanhigh
. -
inExclusiveRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater than
low
and less thanhigh
. -
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 tohigh
. -
inOpenClosedRange(
num low, num high) → Matcher -
Returns a matcher which matches if the match argument is greater than
low
and less than or equal tohigh
. -
isIn(
expected) → Matcher -
Returns a matcher that matches if the match argument is in the expected value. This is the converse of contains.
-
isNot(
matcher) → Matcher -
This returns a matcher that inverts
matcher
to its logical negation. -
lessThan(
value) → Matcher -
Returns a matcher which matches if the match argument is less than the given
value
. -
lessThanOrEqualTo(
value) → Matcher -
Returns a matcher which matches if the match argument is less than or equal to the given
value
. -
matches(
re) → Matcher -
Returns a matcher that matches if the match argument is a string and matches the regular expression given by
re
. -
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(
Iterable expected, bool comparator(a, b), String description) → Matcher -
A pairwise matcher for Iterables.
-
predicate(
bool f(value), [ String description = 'satisfies function' ]) → Matcher -
Returns a matcher that uses an arbitrary function that returns true or false for the actual value.
-
prints(
matcher) → Matcher -
Matches a Function that prints text that matches
matcher
. -
registerException(
error, [ StackTrace stackTrace ]) → void -
Registers an exception that was caught for the current test.
-
reportExpectCall(
StackTrace stack, StringBuffer 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(
expected) → Matcher -
Returns a matches that matches if the value is the same instance as
expected
, using identical. -
setUp(
dynamic callback()) → void -
Registers a function to be run before tests.
-
setUpAll(
dynamic callback()) → void -
Registers a function to be run once before all tests.
-
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 callback()) → void -
Registers a function to be run after tests.
-
tearDownAll(
dynamic callback()) → void -
Registers a function to be run once after all tests.
-
test(
description, dynamic body(), { String testOn, Timeout timeout, skip, tags, Map<String, dynamic> onPlatform }) → void -
Creates a new test case with the given description (converted to a string) and body.
-
testWidgets(
String description, WidgetTesterCallback callback, { bool skip: false, Timeout timeout }) → void -
Runs the
callback
inside the Flutter test environment. -
throwsA(
matcher) → Matcher -
This can be used to match two 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. -
wrapMatcher(
x) → Matcher -
Takes an argument and returns an equivalent Matcher.
Enums
- EnginePhase
-
Phases that can be reached by pumpWidget and TestWidgetsFlutterBinding.pump.
- TestBindingEventSource
-
Parts of the system that can generate pointer events that reach the test binding.
Classes
- AutomatedTestWidgetsFlutterBinding
-
A variant of TestWidgetsFlutterBinding for executing tests in the
flutter test
environment. - CommonFinders
-
Provides lightweight syntax for getting frequently used widget Finders.
- 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.
- Description
-
Matchers build up their error messages by appending to Description objects. This interface is implemented by StringDescription. This interface is unlikely to need other implementations, but could be useful to replace in some cases - e.g. language conversion.
- Finder
-
Searches a widget tree and returns nodes that match a particular pattern.
- Future
-
An object representing a delayed computation.
- isInstanceOf
-
Returns a matcher that matches if an object is an instance of
type
(or a subtype). - LiveTestWidgetsFlutterBinding
-
A variant of TestWidgetsFlutterBinding for executing tests in the
flutter run
environment, on a device. This is intended to allow interactive test development. - Matcher
-
expect Matchers must implement/extend the Matcher class. The base Matcher class has a generic implementation of describeMismatch so this does not need to be provided unless a more clear description is required. The other two methods (matches and describe) must always be provided as they are highly matcher-specific.
- MatchFinder
-
Searches a widget tree and returns nodes that match a particular pattern.
- OnPlatform
-
An annotation for platform-specific customizations for a test suite.
- Point
-
An immutable 2D floating-point x,y coordinate pair.
- Skip
-
An annotation for marking a test suite as skipped.
- 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.
- TestAsyncUtils
-
Utility class for all the async APIs in the
flutter_test
library. - TestFailure
-
An exception thrown when a test assertion fails.
- TestGesture
-
A class for performing gestures in tests.
- TestOn
-
An annotation indicating which platforms a test suite supports.
- TestPointer
-
A class for generating coherent artificial pointer events.
- 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 ImageFit.contain algorithm.
- TestWidgetsFlutterBinding
-
Base class for bindings used by widgets library tests.
- Throws
- Timeout
-
A class representing a modification to the default timeout for a test.
- TypeMatcher
- WidgetController
-
Class that programmatically interacts with widgets.
- WidgetTester
-
Class that programmatically interacts with widgets and the test environment.