2

Widget tests

I know that I can expect exceptions in widget tests:

However, I want to test for an Error or an Exception when running my app using flutter_driver.

Integration tests

Currently, I simply look at the logs when running test_driver and check if the logged exceptions are what I expect. However, that is not ideal and I want to integrate the exceptions into the rest of the integration testing.

flutterDriverLog

I found flutterDriverLog in the flutter_driver library, however, the exceptions do not appear there. It only sends records for the FlutterDriver status, e.g.:

[info ] FlutterDriver: Connecting to Flutter application at ..
[trace] FlutterDriver: Isolate found with number: ..
...

What I am looking for

I would love to have some code like this:

group('Some tests', () {
  test('Button that throws an exception', () async {
    await flutterDriver.tap(find.byType(IconButton));

    // The following property and function do not exist.
    expect(thatExceptionIsThrown, thatMatches('PlatformException(some_error'));
  });
});

How do I do that when running FlutterDriver?

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • 1
    Does it even make sense in integration tests? That's an implementation detail and you'd likely want to test that the error page is shown – Rémi Rousselet Oct 10 '19 at 19:38
  • @RémiRousselet The `PlatformException` can only occur in integration tests, but I want to make sure that it is thrown because otherwise the integration test will have failed to execute a certain task. – creativecreatorormaybenot Oct 10 '19 at 21:27
  • Can't you instead that that the "certain task" succeeded? – Rémi Rousselet Oct 11 '19 at 07:25
  • @RémiRousselet The exception is the best indicator. There is also a visual indicator, but testing for that is almost impossible with `FlutterDriver` and requires restructuring the app itself. However, I do not want to build an app about its integration tests. It should be the other way round. – creativecreatorormaybenot Oct 11 '19 at 12:12

0 Answers0