Commit graph

143 commits

Author SHA1 Message Date
Todd Volkert e19db89a0e
Add basic support for golden image file testing (#17094)
* Add a `matchesGoldenFile()` async matcher that will match
  a finder's widget's rasterized image against a golden file.
* Add support for pluggable image comparison backends
* Add a default backend that does simplistic PNG byte
  comparison on locally stored golden files.
* Add support for `flutter test --update-goldens`, which will
  treat the rasterized image bytes produced during the test
  as the new golden bytes and update the golden file accordingly

Still TODO:

* Add support for the `flutter_test_config.dart` test config hook
* Utilize `flutter_test_config.dart` in `packages/flutter/test`
  to install a backend that retrieves golden files from a dedicated
  `flutter/goldens` repo

https://github.com/flutter/flutter/issues/16859
2018-04-30 10:35:56 -07:00
Todd Volkert dedd180f9f
Fix expectLater to not wrap the delegate in a guard (#17085)
Follow-up to https://github.com/flutter/flutter/pull/17063

https://github.com/flutter/flutter/issues/16859
2018-04-30 10:05:04 -07:00
Todd Volkert 8860627b63
Add WidgetTester.runAsync() (#17029)
This will allow callers to run real async code within a widget test.

https://github.com/flutter/flutter/issues/16859
2018-04-28 15:14:46 -07:00
Todd Volkert 8b99d1d83c
Add expectLater to flutter_test (#17063)
* Wrap `expectLater()` in flutter_tester so that callers can
  wait for the matcher to complete in their tests

https://github.com/flutter/flutter/issues/16859
2018-04-28 13:54:08 -07:00
xster d8f360717f
Add a way to generically go back on both Material and Cupertino scaffold pages (#15602)
* Add a way to generically go back on both Material and Cupertino scaffold pages

* review

* lint

* review

* Fix text assert text
2018-03-19 16:57:05 -07:00
Yegor 973742fe96
[flutter_test] more docs, tests for within; simpler _sizeDistance (#15084)
Document missing value types supported by `within`. Add missing tests. Simplify _sizeDistance implementation.
2018-03-02 15:44:58 -08:00
amirh 0da6bad656
add a matcher for area covered by paths (#14469) 2018-02-06 09:13:51 -08:00
Alexandre Ardhuin 3c379aaf43
whitespace cleanup (#14458) 2018-02-05 22:20:21 +01:00
Alexandre Ardhuin 841d5d7bd5
prefer_const_declarations on local variables (#14358) 2018-02-01 07:51:26 +01:00
Alexandre Ardhuin 0fe1e5bf5b
apply upcoming lint prefer_const_literals_to_create_immutables (#14029) 2018-01-11 08:38:55 +01:00
Hans Muller 83134cd39f
Added find.ancestor to CommonFinders (#13691) 2017-12-20 15:03:58 -08:00
Yegor a75f003b9c
add within matcher for comparing metric-space values (#12908) 2017-11-08 13:36:16 -08:00
Ian Hickson 8fd20b5deb
Text Painting Fuzzer (#12813)
Various improvements (in particular a new painting fuzzer) to the text manual test.

Some additional documentation.

A fix to Stack to remove an LTR bias: make unpositioned children apply "alignment".

Some more debugging information on RichText and Text.

A fix to the flutter tool to not crash when an RPC call throws an exception.
2017-11-01 15:04:43 -07:00
Alexandre Ardhuin 1fce14a31c enable lint prefer_single_quotes (#12665) 2017-10-22 18:11:36 +02:00
Adam Barth 0044ea2dbb Replace usage of FractionalOffset with Alignment (#12348)
Alignment will eventually replace FractionalOffset.
2017-10-02 00:06:24 -07:00
Yegor ba5b5e7f6f only tap on widgets reachable by hit testing (#11767)
* only tap on widgets reachable by hit testing

* use FractionalOffset

* added tests

* check finder finds correct widget

* undo unintentional changes

* address comments

* style fix

* add Directionality in test

* fix analysis warning
2017-09-11 09:46:42 -07:00
Jacob Richman 0229711ba1 Refactor SemanticsData and SemanticsNode to use Diagnosticable. (#11957)
* Refactor SemanticsData and SemanticsNode to use Diagnosticable.

* Switch toStringDeep to take named parameters.
2017-09-11 09:25:58 -07:00
Ian Hickson ca7d2d23cf TextPainter RTL (#11888) 2017-09-07 16:57:38 -07:00
Ian Hickson f235a2c104 RTL: Padding, Flex (#11709)
* Introduce a Directionality inherited widget which sets the ambient LTR vs RTL mode (defaulting to null, which means you cannot use directionality-influenced values).

* Make it possible to configure Padding (including Container.padding and Container.margin) using a directionality-agnostic EdgeInsets variant.

* Provide textDirection and verticalDirection controls on Row and Column to make them RTL-aware.

* Introduce a variant of FractionalOffset based on the EdgeInsets variant. Not yet actually used.

* Fix all the tests that depended on Row defaulting to LTR.
2017-08-28 12:50:24 -07:00
Jacob Richman 8f07a5864b Add hasAGoodToStringDeep and equalsIgnoringHashCodes methods. (#10935)
* Add hasAGoodToStringDeep and equalsIgnoringHashCodes methods.

Methods simplify testing of toStringDeep calls and other cases where
methods return strings containing hash codes.
2017-06-23 14:07:09 -07:00
Hans Muller 80a8c5629e WidgetTester enterText() and showKeyboard() can specify an EditableText ancestor (#9398) 2017-04-14 15:41:30 -07:00
Ian Hickson 3eb87830e9 Constants! Constants everywhere! (#9286)
Aggressively apply the const lint.
2017-04-07 12:24:32 -07:00
Ian Hickson e355c60124 Add a timeout to pumpAndSettle. (#9195) 2017-04-05 12:27:42 -07:00
Ian Hickson d709f18cd2 Do not swallow exceptions in guarded functions. (#9064) 2017-03-30 09:50:30 -07:00
Adam Barth 142922deb4 Add WidgetTester.hasRunningAnimation (#8886)
Fixes #4017
2017-03-20 13:32:00 -07:00
Ian Hickson 8eac6cd0da Test API improvements: pumpAndSettle, autogenerate pointer IDs (#8751) 2017-03-13 16:27:15 -07:00
Chris Bracken 895f3e6350 Declare locals final where not reassigned (flutter_test) (#8569) 2017-03-03 17:51:01 -08:00
Phil Quitslund a002e72022 Bump to test 0.12.20. (#8349)
* Bump to test `0.12.20`.

Some test `0.12.20` highlights:
  * introduces `expectLater()`  that returns a `Future` that completes when the matcher has finished running
  * deprecates the `verbose` parameter to `expect()` and the `formatFailure()` (to be removed in `0.13.0`)

Otherwise:
  * to keep up w/ the deprecation of `verbose`, removes `widget_tester` API to pass `verbose` flag (alternatively we could suppress the warning for now)

* Update stack manipulation.

* Fix framecount.
2017-02-23 15:08:25 -08:00
zhenqiu1101 47666af54c Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant. (#7944)
* Add find.descendant API to support find descendants of an element by passing the current element and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.

* Add find.descendant API to support find descendants of an element by passing the current element finder and the finder of descendant.
2017-02-07 14:46:29 -08:00
Ian Hickson 79c8e5c7c7 Add a toString to Simulation (#7364)
Also, make hasOneLineDescription more discerning.
Also, add a test for hasOneLineDescription.
Also, add a test for GravitySimulation, to test the toString.
2017-01-05 16:33:40 -08:00
Ian Hickson e08c3c3bdc moreOrLessEquals matcher for floating point numbers (#7358)
```dart
expect(x, moreOrLessEquals(0.0));
```

...for those cases where `x` might be 1e-11 or whatever.

Also, be more resilient when dumping the tree from inside the test framework.
Also, add an assert that helped me debug something the other day.
2017-01-05 14:51:01 -08:00
Yegor 995fcdc92b add description to by-predicate finders (#6362)
Add an option to provide a custom description to predicate
finders. Without a custom description we default to printing the
predicate function's signature, which is not all that useful.

Use this new option in the driver extension to print the text of the
sought after tooltip.
2016-10-17 17:16:22 -07:00
Ian Hickson 9e673853e5 Turn off AnimationControllers when not in use (#5902)
This requires all AnimationController objects to be given a
TickerProvider, a class that can create the Ticker.

It also provides some nice mixins for people who want to have their
State provide a TickerProvider. And a schedulerTickerProvider for those
cases where you just want to see your battery burn.

Also, we now enforce destruction order for elements.
2016-09-26 10:57:10 -07:00
Ian Hickson 1152fd60f6 Adds tester.pumpUntilNoTransientCallbacks (#5696)
Fixes https://github.com/flutter/flutter/issues/5234
2016-09-01 12:42:38 -07:00
Ian Hickson ea6bf4706a Fix the losing of state when pushing opaque routes (#5624)
Fixes https://github.com/flutter/flutter/issues/5283

Other changes in this patch:

Rename OffStage to Offstage.
Fixes https://github.com/flutter/flutter/issues/5378

Add a lot of docs.

Some minor punctuation and whitespace fixes.
2016-08-29 11:28:37 -07:00
pq 3e9067a4ec Dead code and switch cleanup (continued).
Prep to get us ready to pull in a new dev SDK and bump our analyzer DEP.

* updates `crypto` (required by fresh analyzer)
* fixes newly flagged dead code warnings
* fixes switches that fall through and don't return
2016-06-16 09:45:37 -07:00
Adam Barth b1b6271683 Use "call" instead of "invoke" (#4177)
For consistency.

Fixes #4142
2016-05-24 17:53:04 -07:00
Ian Hickson ef563c485e Handle stack traces that don't give column numbers (#4016) 2016-05-18 12:34:43 -07:00
Ian Hickson f284c1a049 Fix tests (#3977)
Also, make sure that broken tests actually break the bots.

And add a test to make sure that keeps happening.
2016-05-17 12:45:37 -07:00
Ian Hickson 3252701753 Make it possible to run tests live on a device (#3936)
This makes it possible to substitute 'flutter run' for 'flutter test'
and actually watch a test run on a device.

For any test that depends on flutter_test:

1. Remove any import of 'package:test/test.dart'.

2. Replace `testWidgets('...', (WidgetTester tester) {`
      with `testWidgets('...', (WidgetTester tester) async {`

3. Add an "await" in front of calls to any of the following:
    * tap()
    * tapAt()
    * fling()
    * flingFrom()
    * scroll()
    * scrollAt()
    * pump()
    * pumpWidget()

4. Replace any calls to `tester.flushMicrotasks()` with calls to
   `await tester.idle()`.

There's a guarding API that you can use, if you have particularly
complicated tests, to get better error messages. Search for
TestAsyncUtils.
2016-05-16 12:53:13 -07:00
Ian Hickson 91dd969966 Refactor the test framework (#3622)
* Refactor widget test framework

Instead of:

```dart
  test("Card Collection smoke test", () {
    testWidgets((WidgetTester tester) {
```

...you now say:

```dart
  testWidgets("Card Collection smoke test", (WidgetTester tester) {
```

Instead of:

```dart
  expect(tester, hasWidget(find.text('hello')));
```

...you now say:

```dart
  expect(find.text('hello'), findsOneWidget);
```

Instead of the previous API (exists, widgets, widget, stateOf,
elementOf, etc), you now have the following comprehensive API. All these
are functions that take a Finder, except the all* properties.

* `any()` - true if anything matches, c.f. `Iterable.any`
* `allWidgets` - all the widgets in the tree
* `widget()` - the one and only widget that matches the finder
* `firstWidget()` - the first widget that matches the finder
* `allElements` - all the elements in the tree
* `element()` - the one and only element that matches the finder
* `firstElement()` - the first element that matches the finder
* `allStates` - all the `State`s in the tree
* `state()` - the one and only state that matches the finder
* `firstState()` - the first state that matches the finder
* `allRenderObjects` - all the render objects in the tree
* `renderObject()` - the one and only render object that matches the finder
* `firstRenderObject()` - the first render object that matches the finder

There's also `layers' which returns the list of current layers.

`tap`, `fling`, getCenter, getSize, etc, take Finders, like the APIs
above, and expect there to only be one matching widget.

The finders are:

 * `find.text(String text)`
 * `find.widgetWithText(Type widgetType, String text)`
 * `find.byKey(Key key)`
 * `find.byType(Type type)`
 * `find.byElementType(Type type)`
 * `find.byConfig(Widget config)`
 * `find.byWidgetPredicate(WidgetPredicate predicate)`
 * `find.byElementPredicate(ElementPredicate predicate)`

The matchers (for `expect`) are:

 * `findsNothing`
 * `findsWidgets`
 * `findsOneWidget`
 * `findsNWidgets(n)`
 * `isOnStage`
 * `isOffStage`
 * `isInCard`
 * `isNotInCard`

Benchmarks now use benchmarkWidgets instead of testWidgets.

Also, for those of you using mockers, `serviceMocker` now automatically
handles the binding initialization.

This patch also:

* changes how tests are run so that we can more easily swap the logic
  out for a "real" mode instead of FakeAsync.

* introduces CachingIterable.

* changes how flutter_driver interacts with the widget tree to use the
  aforementioned new API rather than ElementTreeTester, which is gone.

* removes ElementTreeTester.

* changes the semantics of a test for scrollables because we couldn't
  convince ourselves that the old semantics made sense; it only worked
  before because flushing the microtasks after every event was broken.

* fixes the flushing of microtasks after every event.

* Reindent the tests

* Fix review comments
2016-04-29 13:23:27 -07:00
Hans Muller 22e8d85d16 Enhance Finder toString() (#3458)
* Enhance Finder toString()
2016-04-21 12:13:51 -07:00
Yegor f3a4f722c4 [flutter_test] new WidgetTester API based on finder objects (#3288) 2016-04-13 23:40:15 -07:00