testController<S extends SuperController, T> function
- @isTest
- String description, {
- required S build(),
- required T state(
- S controller
- void onEnable(
- S controller
- void onAlive(
- S controller
- void onDisable(
- S controller
- FutureOr<
void> setUp()?, - T seed()?,
- FutureOr<
void> act(- S controller
- Duration? wait,
- int skip = 0,
- List<
T> expect()?, - FutureOr<
void> verify(- S controller
- Object errors()?,
- FutureOr<
void> tearDown()?, - dynamic tags,
Test case for a SuperController
object.
The testController function is used to define a test case for a SuperController
object.
It takes various parameters to configure the test case, including the description
of the test,
the build
function to create the SuperController
object, functions for handling enable, alive,
and disable states, setup and teardown functions, initial state seed
, actions to perform on the controller,
a wait duration, expected outcomes, verification functions, error handling, and optional tags
for categorization.
Example usage:
testController<MyController, int>(
'MyController test',
build: () => MyController(),
state: (controller) => controller.myState,
onEnable: () {
// Handle the enable state.
},
onAlive: () {
// Handle the alive state.
},
onDisable: () {
// Handle the disable state.
},
setUp: () {
// Perform setup operations.
},
seed: () => 10,
act: (controller) async {
// Perform actions on the controller.
},
wait: const Duration(seconds: 1),
expect: () => [10],
verify: (controller) async {
// Perform additional verifications.
},
tearDown: () {
// Perform teardown operations.
},
);
In the above example, the testController function is used to define a test case for a custom
SuperController
object that holds an integer value. The test case includes a description, a build
function to create the SuperController
object, functions to handle the enable, alive, and disable states,
setup and teardown functions, an initial state seed
, actions to perform on the controller, a wait duration,
expected outcomes, verification functions, and teardown operations. The test case can be executed by running the test suite.
The testController function provides a convenient way to define and organize test cases for
SuperController
objects in unit tests.
Implementation
@isTest
void testController<S extends SuperController, T>(
String description, {
required S Function() build,
required T Function(S controller) state,
void Function(S controller)? onEnable,
void Function(S controller)? onAlive,
void Function(S controller)? onDisable,
FutureOr<void> Function()? setUp,
T Function()? seed,
FutureOr<void> Function(S controller)? act,
Duration? wait,
int skip = 0,
List<T> Function()? expect,
FutureOr<void> Function(S controller)? verify,
Object Function()? errors,
FutureOr<void> Function()? tearDown,
dynamic tags,
}) {
test.test(
description,
() async {
await _controllerTest<S, T>(
setUp: setUp,
build: build,
state: state,
seed: seed,
onEnable: onEnable,
onAlive: onAlive,
onDisable: onDisable,
act: act,
wait: wait,
skip: skip,
expect: expect,
verify: verify,
errors: errors,
tearDown: tearDown,
);
},
tags: tags,
);
}