toProcessPaper<U extends Unit<Paper>, S extends UnitState<Paper, U>> static method

  1. @isTest
void toProcessPaper<U extends Unit<Paper>, S extends UnitState<Paper, U>>(
  1. String description, {
  2. required U unit,
  3. void setup(
    1. S state,
    2. AgentValidator agentValidator
    )?,
  4. required Paper? paper,
  5. required void test(
    1. S state,
    2. AgentValidator agentValidator
    ),
  6. String? testOn,
  7. Timeout? timeout,
  8. dynamic skip,
  9. dynamic tags,
  10. Map<String, dynamic>? onPlatform,
  11. int? retry,
})

Create a test to verify the operations when U unit handles paper with the given description. U is type the of target unit. S is the type of corresponding state of U.

unit is the Unit for testing.

setup is for initializing and preparing required dependencies for the unit. 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.

testOn is equivalent to testOn of test in flutter_test.

timeout is equivalent to timeout of test in flutter_test.

skip is equivalent to skip of test in flutter_test.

tags is equivalent to tags of test in flutter_test.

onPlatform is equivalent to onPlatform of test in flutter_test.

retry is equivalent to retry of test in flutter_test.

Refer to TestUnit for an example.

Implementation

@isTest
static void
    toProcessPaper<U extends Unit<Paper>, S extends UnitState<Paper, U>>(
  String description, {
  required U unit,
  void Function(S state, AgentValidator agentValidator)? setup,
  required Paper? paper,
  required void Function(S state, AgentValidator agentValidator) test,
  String? testOn,
  flutter_test.Timeout? timeout,
  dynamic skip,
  dynamic tags,
  Map<String, dynamic>? onPlatform,
  int? retry,
}) {
  final tester = UnitTestingEnvironment();

  flutter_test.test(
    description,
    () async {
      await tester.setupTestingUnit(unit);
      final state = tester.context?.state;
      final agentValidator = tester.network.agentValidator;
      setup?.call(state, agentValidator);
      if (paper != null) {
        await tester.commandTestingUnit(paper);
      }
      test(state, tester.network.agentValidator);
    },
    testOn: testOn,
    timeout: timeout,
    skip: skip,
    tags: tags,
    onPlatform: onPlatform,
    retry: retry,
  );
}