TestPlatformVariant class
A TestVariant that automates multi-platform widget testing by cycling through a defined matrix of target operating systems (TargetPlatform).
This variant dynamically overrides the global debugDefaultTargetPlatformOverride
state during the setUp phase, ensuring consistent environment replication across test runners.
All platform overrides are automatically restored back to null during tearDown.
Example Usage:
final platformVariant = TestPlatformVariant.mobile(description: 'Biometric Login');
final customPlatformVariant = TestPlatformVariant(
description: 'Custom Suite',
values: {TargetPlatform.android, TargetPlatform.macOS},
);
testWidgets('Should render custom look-and-feel', variant: platformVariant, (tester) async {
final currentPlatform = platformVariant.current;
print('Testing architecture on: \${currentPlatform.name}');
// Your test assertion logic...
});
- Inheritance
-
- Object
- TestVariant<
TargetPlatform> - TestPlatformVariant
Constructors
-
TestPlatformVariant({required String description, Set<
TargetPlatform> ? values}) - Creates a TestPlatformVariant that executes tests against a custom set of platforms.
- TestPlatformVariant.all({required String description})
-
Creates a TestPlatformVariant bundled with all mainstream operating systems.
factory
- TestPlatformVariant.desktop({required String description})
-
Creates a TestPlatformVariant focused strictly on computer desktop operating systems.
factory
- TestPlatformVariant.mobile({required String description})
-
Creates a TestPlatformVariant focused strictly on portable smartphone environments.
factory
Properties
- current → TargetPlatform
-
Retrieves the operating system platform currently active in the running test slice.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ Set<
TargetPlatform> -
Returns an iterable of the variations that this test dimension represents.
final
Methods
-
describeValue(
TargetPlatform value) → String -
Formats the console log output for the active test permutation block.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setUp(
TargetPlatform value) → Future< void> -
Configures the Flutter testing framework environment prior to running the test block.
override
-
tearDown(
TargetPlatform value, covariant Object? memento) → Future< void> -
Cleans up target environment modifications made during the setUp phase.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited