TestDeviceVariant class
A TestVariant that automates responsive and multi-platform widget testing by cycling through a matrix of simulated devices.
This variant dynamically overrides the target platform (TargetPlatform),
physical screen size (Size), and standardizes the device pixel ratio to 1.0
during the setUp phase, ensuring consistent environment replication across test runners.
All overrides are automatically restored during tearDown.
A TestVariant that automates responsive and multi-platform widget testing by cycling through a matrix of simulated devices.
This variant dynamically overrides the target platform (TargetPlatform),
physical screen size (Size), and standardizes the device pixel ratio to 1.0
during the setUp phase, ensuring consistent environment replication across test runners.
All overrides are automatically restored during tearDown.
Example Usage:
final deviceVariant = TestDeviceVariant.mobile(description: 'Authentication Flow');
final deviceVariant = TestDeviceVariant.tablets(description: 'Authentication Flow');
final deviceVariant = TestDeviceVariant.desktop(description: 'Authentication Flow');
or to use all predefined devices and yours respective platforms in the package
final deviceVariant = TestDeviceVariant(description: 'Authentication Flow');
or custom your property devices
final customDeviceVariant = TestDeviceVariant(
description: 'Custom Device',
values: {TestDevices.iphoneStandard,
DeviceVariantConfig(
platform: TargetPlatform.android,
info: 'Smartphone XYZ (360x420)',
size: Size(360.0, 420.0),
) TestDevices.macosDesktop,},
);
testWidgets('Should render login components properly', variant: deviceVariant, (tester) async {
final currentDevice = deviceVariant.current;
print('Testing on: ${currentDevice.info}');
await tester.pumpWidget(const MyApp());
// Expects here...
});
- Inheritance
-
- Object
- TestVariant<
DeviceVariantConfig> - TestDeviceVariant
Constructors
-
TestDeviceVariant({required String description, Set<
DeviceVariantConfig> ? values}) -
Creates a TestDeviceVariant that executes tests against a custom set of devices,
or defaults to
TestDevices.allif novaluesare provided. - TestDeviceVariant.desktop({required String description})
-
Creates a TestDeviceVariant focused strictly on laptop and desktop monitors.
factory
- TestDeviceVariant.mobile({required String description})
-
Creates a TestDeviceVariant focused strictly on smartphones and mobile devices.
factory
- TestDeviceVariant.tablets({required String description})
-
Creates a TestDeviceVariant focused strictly on tablets and iPad dimensions.
factory
Properties
- current → DeviceVariantConfig
-
Retrieves the configuration of the device 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<
DeviceVariantConfig> -
Returns an iterable of the variations that this test dimension represents.
final
Methods
-
describeValue(
DeviceVariantConfig 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(
DeviceVariantConfig value) → Future< void> -
Configures the Flutter testing framework environment prior to running the test block.
override
-
tearDown(
DeviceVariantConfig value, covariant Object? memento) → Future< void> -
Cleans up 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