TestController class
Controller that allows for the creation, loading, saving, and running of automated tests.
Constructors
-
TestController({Map<
String, PageRoute> ? customRoutes, TestStepDelays delays = const TestStepDelays(), GoldenImageWriter goldenImageWriter = TestStore.goldenImageWriter, int maxCommonSearchDepth = 3, AsyncCallback? onReset, bool screenshotOnFail = false, String? selectedSuiteName, bool stopOnFirstFail = false, TestStepRegistry? registry, TestImageReader testImageReader = TestStore.testImageReader, TestReader testReader = TestStore.testReader, WidgetBuilder? testReportBuilder, Level testReportLogLevel = Level.INFO, TestReporter testReporter = TestStore.testReporter, WidgetBuilder? testSuiteReportBuilder, TestWriter testWriter = TestStore.testWriter, List<VariableResolver> ? variableResolvers, Map<String, dynamic> ? variables}) - A controller for a TestRunner that can create, run, load, and save automated tests.
Properties
- currentTest ↔ Test
-
Returns the current from the controller. This will never be
null
.getter/setter pair -
customRoutes
→ Map<
String, PageRoute> -
Returns the custom routes, sorted by the display name.
no setter
- delays → TestStepDelays
-
The delays that tests should wait for.
final
- goldenImageWriter → GoldenImageWriter
-
Writer that saves golden images for a particular device.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxCommonSearchDepth → int
-
Defines how far down a widget tree a Testable widget should look for a
supported widget for the purposes of getting or setting values and errors.
final
- onReset → AsyncCallback?
-
Callback function that the application must register with the controller
so that when a reset is requested by a test, the application properly
resets to the initial state.
final
- registry → TestStepRegistry
-
Returns the registry that is being used by the controller.
no setter
-
resetStream
→ Stream<
void> -
Returns the stream that receives an event whenever a reset is called.
no setter
- runningTest → bool
-
Returns whether or not the controller is actively running a test now or
not.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
screencapStream
→ Stream<
CaptureContext> -
Returns the stream that will fire screep capture requests on.
no setter
- screenshotOnFail → bool
-
Defines whether the framework should take a screenshot automatically
whenever a failure is detected or not.
final
- selectedSuiteName ↔ String?
-
The currently selected test suite name.
getter/setter pair
- sleep ← ProgressValue?
-
Informs the controller that a sleep status update has happened.
no getter
-
sleepStream
→ Stream<
ProgressValue?> -
Returns the stream that will fire updates as a test is sleeping / waiting.
no setter
- state → TestControllerState
-
Returns the current state for the test controller.
no setter
- status ← String
-
Informs the controller that a test status update has happened.
no getter
-
statusStream
→ Stream<
String> -
Returns the stream that will fire updates when a test status changes.
no setter
- step ← ProgressValue?
-
Informs the controller that a test step update has happened.
no getter
-
stepStream
→ Stream<
ProgressValue?> -
Returns the stream that will fire updates when a test moves from step to
step.
no setter
- stopOnFirstFail → bool
-
Defines whether or not the framework should stop on the first failed step
or keep going and executing subsequent steps.
final
- testImageReader → TestImageReader
-
The image reader to read images for golden image comparisons.
final
-
variables
→ Map<
String, dynamic> -
Returns an unmodifiable map of all the currently set variables.
no setter
Methods
-
cancelRunningTests(
[Duration timeout = const Duration(minutes: 5)]) → Future< void> - Canceles any currently running test. The current step will be the last to execute, but this may still take a while as the current second could be a long running step.
-
clearCustomRoutes(
) → void - Clears all the custom routes.
-
clearGlobalVariables(
) → void - Clears all the currently set global variables.
-
clearTestVariables(
) → void - Clears all the currently set test variables.
-
clearVariables(
) → void - Clears all the variables.
-
dispose(
) → void - Disposes the controller. Once disposed, a controller can not be reused.
-
execute(
{String? name, TestReport? report, bool reset = true, Duration? stepTimeout, required List< TestStep> steps, bool submitReport = true, String? suiteName, TestSuiteReport? testSuiteReport, Duration? testTimeout, required int version}) → Future<TestReport> -
Executes a series of tests steps. This accepts the
name
of the test which may benull
or empty. Thereset
defines if the controller should ask the application to perform a full reset before running or if it should attempt to run for the current state. -
executeStep(
{required CancelToken cancelToken, required TestReport report, required TestStep step, bool subStep = true}) → Future< bool> -
Executes a single
step
and attaches the execution information to thetestReport
. ThecancelToken
allows the step to be cancelled. Whenever a step has a loop or a long running task, it should listen to the stream from the token or read the flag from the token. -
executeTest(
{required Test test, TestReport? report}) → Future< TestReport> -
Executes a single
test
. This will reset the application and submit the report. If thereport
is set it will be used, otherwise a net-newTestReport
will be created and returned. -
exportCurrentTest(
{bool clear = true, required BuildContext context}) → Future< bool> -
Attempts to export the current test via the
testWriter
value. This will returntrue
if and only if the currenttestWriter
both returnstrue
and no exceptions were thrown along the way. -
getVariable(
String variableName) → dynamic - Returns the variable from the controller. This will first iterate through each VariableResolver given to the controller and will return the value from the first resolver that did not throw an UnknownVariableException.
-
loadTests(
BuildContext? context, {String? suiteName}) → Future< List< PendingTest> ?> - Loads the list of tests from the assigned TestReader. This accepts the BuildContext to allow the reader to provide visual feedback to the user in case the load takes a while.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerCustomRoute(
String display, PageRoute? route) → void -
Registers a custom
route
with the framework. These routes will be displayed on theTestStepsDialog
and TestStepsPage. Thedisplay
is the string to display in a ListTile's title to trigger navigation to theroute
. If the route isnull
, this will remove any route registered to thedisplay
. If thedisplay
is already registered, it will be replaced with the newroute
-
removeGlobalVariable(
{required String variableName}) → void -
Removes the value for
variableName
globally. -
removeTestVariable(
{required String variableName}) → void -
Removes the value for
variableName
for the current test. -
reset(
) → Future< void> - Requests the application to perform a reset.
-
resolveVariable(
dynamic input) → dynamic -
Resolves the given input with any potential variable on the controller.
Variable values use the mustache format and must begin with
{{
and end with}}
. If the input is not marked as a variable or there is no variable with the matching key registered then the input will be return unaltered. -
runPendingTests(
List< PendingTest> tests, [Duration waitTimeout = _kSuiteStartTimeout]) → Future<TestSuiteReport> -
Runs a series of
tests
. For full runs, this is more memory efficient as it will only load the tests as needed. -
runTests(
List< Test> tests, {Duration? stepTimeout, Duration waitTimeout = _kSuiteStartTimeout}) → Future<TestSuiteReport> -
Runs a series of
tests
. This is useful for smaller numbers of in-memory tests but the runPendingTests should be prefered for full application runs or for CI/CD pipelines as that only loads the bare minimum data up front and then loads the full test data on an as needed basis. -
screencap(
) → Future< Uint8List?> - Executes a screen capture for the application. As a note, depending on the device this may take several seconds. The screenshot call is fully async so this will wait until up to TestStepDelays.screenshot for the response.
-
setGlobalVariable(
{required dynamic value, required String variableName}) → void -
Sets the variable with the
variableName
to thevalue
to be accessible by all running tests. -
setTestVariable(
{required dynamic value, required String variableName}) → void -
Sets the variable with the
variableName
to thevalue
to be accessible by the currently running test. -
submitReport(
TestReport report) → Future< bool> - Submits the test report through the TestReporter.
-
toBehaviorDrivenDescription(
Test test) → String -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of(
BuildContext context) → TestController? -
Returns the TestController provided by the widget tree. This will never
throw an exception but may return
null
if no controller is available on the widget tree.