dartup_test library Null safety

Classes

CustomMatching
CustomMatcher that can make assertions about prices with:
Expectation<T>
A captured method or property accessor -> a function that returns a value.
Fake
A stand-in for another object which cannot be used except for specifically overridden methods.
IsEmail
Mock
Extend or mixin this class to mark the implementation as a Mock.
MockBloc<E, S>
Extend or mixin this class to mark the implementation as a MockBloc.
MockCubit<S>
Extend or mixin this class to mark the implementation as a MockCubit.
VerificationResult
Information about a stub call verification.
When<T>
Result of when which enables methods to be stubbed via

Extensions

ListOfVerificationResult
Returns the list of argument lists which were captured within verifyInOrder.
MatcherExtension
StreamMatcherTestExtension
VerificationExtension
WidgetTesterExtension

Properties

emailRegex RegExp
RFC 2821, 2822 Compliant from https://regexlib.com
final
emitsNothing StreamMatcher
final
isEmail CustomMatching
final
isEmptyStream StreamMatcher
final
isNotEmptyStream StreamMatcher
final
isUrl CustomMatching
final
untilCalled Future<Invocation> Function<T>(T _())
Returns a future Invocation that will complete upon the first occurrence of the given invocation.
read-only
urlRegex RegExp
final
verify → _Verify
Verify that a method on a mock object was called with the given arguments.
read-only
verifyInOrder List<VerificationResult> Function<T>(List<T Function()> recordedInvocations)
Verifies that a list of methods on a mock object have been called with the given arguments. For example:
read-only
verifyNever → _Verify
Verify that a method on a mock object was never called with the given arguments.
read-only
when When<T> Function<T>(T x())
Create a stub method response.
read-only

Functions

any<T>({String? named, Matcher? that}) → T
An argument matcher that matches any argument passed in.
blocTest<B extends BlocBase<State>, State>(String description, {FutureOr<void> setUp()?, required B build(), State seed()?, dynamic act(B bloc)?, Duration? wait, int skip = 0, dynamic expect()?, dynamic verify(B bloc)?, dynamic errors()?, FutureOr<void> tearDown()?, dynamic tags}) → void
Creates a new bloc-specific test case with the given description. blocTest will handle asserting that the bloc emits the expected states (in order) after act is executed. blocTest also handles ensuring that no additional states are emitted by closing the bloc stream before evaluating the expectation.
captureAny<T>({String? named, Matcher? that}) → T
An argument matcher that captures any argument passed in.
clearInteractions(dynamic mock) → void
Clear the collected interactions with mock.
containsKey(dynamic key) Matcher
containsSomeOf(Iterable expected) Matcher
countOf(int expectedCount) StreamMatcher
emitsErrorOfType<E>() StreamMatcher
hasThrow<E>() Matcher
isAfter(DateTime expectedDateTime) Matcher
isAtSameMomentAs(DateTime expectedDateTime) Matcher
isBefore(DateTime expectedDateTime) Matcher
isCloseTo(DateTime expectedDateTime, {int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) Matcher
isLongerThan({int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) Matcher
isShorterThan({int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) Matcher
isTestFailure(dynamic message) Matcher
Returns a matcher that matches a TestFailure with the given message.
logInvocations(List<Mock> mocks) → void
Print all collected invocations of any mock methods of mocks.
matcher(String description, MatcherFunction matches) CustomMatching
materialTestApp(Widget widget, {String title = 'test', ThemeData? theme}) MaterialApp
registerFallbackValue<T>(T value) → void
Allows any and captureAny to be used on parameters of type T.
reset(dynamic mock) → void
Clear stubs of, and collected interactions with mock.
resetMocktailState() → void
Reset the state of Mocktail, typically for use between tests.
testBloc<B extends BlocBase<State>, State>({FutureOr<void> setUp()?, required B build(), State seed()?, dynamic act(B bloc)?, Duration? wait, int skip = 0, dynamic expect()?, dynamic verify(B bloc)?, dynamic errors()?, FutureOr<void> tearDown()?}) Future<void>
Internal blocTest runner which is only visible for testing. This should never be used directly -- please use blocTest instead.
throwOnMissingStub(Mock mock, {void exceptionBuilder(Invocation)?}) → void
Opt-into Mock throwing NoSuchMethodError for unimplemented methods.
throwsTestFailure(dynamic message) Matcher
Returns a matcher that matches a callback or Future that throws a TestFailure with the given message.
verifyNoMoreInteractions(dynamic mock) → void
Ensure no redundant invocations occur.
verifyZeroInteractions(dynamic mock) → void
Ensure interactions never happened on a mock.
whenListen<State>(BlocBase<State> bloc, Stream<State> stream, {State? initialState}) → void
Creates a stub response for the listen method on a bloc. Use whenListen if you want to return a canned Stream of states for a bloc instance.

Typedefs

Answer<T> = T Function(Invocation invocation)
Returns a value dependent on the details of an invocation.
MatcherFunction = bool Function(dynamic a, Map b)

Exceptions / Errors

MissingStubError
An error which is thrown when no stub is found which matches the arguments of a real method call on a mock object.