toProcessPaper<U extends UnitWidget<Paper>, S extends UnitWidgetState<Paper, U>> static method

  1. @isTest
void toProcessPaper<U extends UnitWidget<Paper>, S extends UnitWidgetState<Paper, U>>(
  1. String description, {
  2. required U create(
    1. UnitWidgetState<Paper, UnitWidget<Paper>> s
    ),
  3. void setup(
    1. S state,
    2. AgentValidator agentValidator
    )?,
  4. required Paper? paper,
  5. required void test(
    1. WidgetTester tester,
    2. S state,
    3. AgentValidator agentValidator
    ),
  6. bool? skip,
  7. Timeout? timeout,
  8. bool semanticsEnabled = true,
  9. TestVariant<Object?> variant = const flutter_test.DefaultTestVariant(),
  10. dynamic tags,
  11. int? retry,
  12. 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 target paper need to test the operation of handling. The testing will command the unit created to process paper after setup.

test is the operation for verify the test case.

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 toProcessPaper<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 void Function(
    flutter_test.WidgetTester tester,
    S state,
    AgentValidator agentValidator,
  ) test,
  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;
        setup?.call(state, agentValidator);
        if (paper != null) {
          await tester.commandTestingUnit(paper);
        }
        test(widgetTester, state, agentValidator);
      });
    },
    skip: skip,
    timeout: timeout,
    semanticsEnabled: semanticsEnabled,
    variant: variant,
    tags: tags,
    retry: retry,
    experimentalLeakTesting: experimentalLeakTesting,
  );
}