widget_driver_generator 1.3.0 copy "widget_driver_generator: ^1.3.0" to clipboard
widget_driver_generator: ^1.3.0 copied to clipboard

This package provides generators for WidgetDriver to automate the creation of your TestDrivers and WidgetDriverProviders

example/README.md

Implement a Driver inside your project #

@GenerateTestDriver()
class MyDriver extends WidgetDriver {
  ...

  @TestDriverDefaultValue(1)
  int get value => _someService.value;

  @TestDriverDefaultValue()
  void doSomething() {
    ...
  }

  @TestDriverDefaultValue('The string')
  String giveMeSomeString() {
    return _someService.getSomeString();
  }

  @TestDriverDefaultFutureValue(123)
  Future<int> giveMeSomeIntSoon() {
    return _someService.getSomeIntSoon();
  }
}

You can also pass data from the widget to the driver #

class MyDriver extends WidgetDriver {
  final SomeType someNamedVariable;
  final SomeType somePositionalVariable;

  MyDriver(
    @driverProvidableProperty this.somePositionalVariable, {
    @driverProvidableProperty required this.someNamedVariable
  });

  ...
}

class MyWidget extends DriveableWidget<MyDriver> {

  @override
  Widget build(BuildContext context) {
    ...
  }

  @override
  WidgetDriverProvider<MyDriver> get driverProvider => $MyDriverProvider(
    somePositionalVariable: xyz,
    someNamedVariable: zyx,
  );
}

This works with named, positional and/or optional variables.

Note: Do use this carefully. This is only intended to pass model data to the driver. (like when clicking on a list item) Try not to use this for providing repositories, to avoid coupling and ease tests.

Generate the code #

In order to generate TestDrivers and WidgetDriverProviders just run this command:

dart run build_runner build --delete-conflicting-outputs
1
likes
120
pub points
33%
popularity

Publisher

verified publisherbmwtech.dev

This package provides generators for WidgetDriver to automate the creation of your TestDrivers and WidgetDriverProviders

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, dart_style, source_gen, widget_driver_annotation, yaml

More

Packages that depend on widget_driver_generator