toReceivePaper<U extends UnitWidget<Paper> , S extends UnitWidgetState<Paper, U> > static method
- @isTest
- String description, {
- required U create(),
- void setup(
- S state,
- AgentValidator agentValidator
- required Paper paper,
- required Agent<
Paper> from(- S state
- required dynamic expected,
- bool? skip,
- Timeout? timeout,
- bool semanticsEnabled = true,
- TestVariant<
Object?> variant = const flutter_test.DefaultTestVariant(), - dynamic tags,
- int? retry,
- LeakTesting? experimentalLeakTesting,
Create a test to verify the operations when U
unit widget handles paper
with the given description
.
U
is type the of target unit. S
is the type of corresponding state of U
.
create
is the method to create the target unit widget.
The input s
is convenient for inject parent state to the widget.
setup
is for initializing and preparing required dependencies for target widget.
setup
is called at very first. setup
is optional.
paper
is the paper will be reported by the child from
.
from
is function to return the agents that will send paper
to the widget.
expected
is the matcher of the expected paper.
skip
is equivalent to skip
of testWidgets
in flutter_test.
timeout
is equivalent to timeout
of testWidgets
in flutter_test.
semanticsEnabled
is equivalent to semanticsEnabled
of testWidgets
in flutter_test.
variant
is equivalent to variant
of testWidgets
in flutter_test.
tags
is equivalent to tags
of testWidgets
in flutter_test.
retry
is equivalent to retry
of testWidgets
in flutter_test.
experimentalLeakTesting
is equivalent to experimentalLeakTesting
of testWidgets
in flutter_test.
Refer to TestUnitWidget for an example.
Implementation
@isTest
static void toReceivePaper<U extends UnitWidget<Paper>,
S extends UnitWidgetState<Paper, U>>(
String description, {
required U Function(UnitWidgetState s) create,
void Function(S state, AgentValidator agentValidator)? setup,
required Paper paper,
required Agent Function(S state) from,
required dynamic expected,
bool? skip,
flutter_test.Timeout? timeout,
bool semanticsEnabled = true,
flutter_test.TestVariant<Object?> variant =
const flutter_test.DefaultTestVariant(),
dynamic tags,
int? retry,
LeakTesting? experimentalLeakTesting,
}) {
final tester = UnitTestingEnvironment();
flutter_test.testWidgets(
description,
(flutter_test.WidgetTester widgetTester) async {
await widgetTester.runAsync(() async {
await tester.setupTestingUnitWidget(create, widgetTester);
final state = tester.context?.state;
final agentValidator = tester.network.agentValidator;
final child = from(state);
setup?.call(state, agentValidator);
if (child is UnitAgent) {
await child.init();
}
final listener = AgentTestingSupporter().getReporter(child);
final output = await listener?.getPaper(paper);
flutter_test.expect(output, expected);
});
},
skip: skip,
timeout: timeout,
semanticsEnabled: semanticsEnabled,
variant: variant,
tags: tags,
retry: retry,
experimentalLeakTesting: experimentalLeakTesting,
);
}