5

I have setted up Flutter Integration Testing on my project as defined here: https://flutter.dev/docs/testing/integration-tests

I used the following devDepencendies:

integration_test: ^1.0.0
flutter_test:
  sdk: flutter
flutter_driver:
  sdk: flutter

The test driver is just a C&P from project page:

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();

The final test:

void main() {
    IntegrationTestWidgetsFlutterBinding.ensureInitialized();

    testWidgets('CPCSA-TC-016: Vehicle Card with no alert',
    (WidgetTester tester) async {
        app.main();
        // Execute test code. 
    });
}

Finally I run my tests with

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/test.dart

Which is basically fine, but it compiles at every execution and this is very time consuming. Is there a chance that I can run the integration test and have the same hot reload feature as I would have for regular development? How to achieve this?

Or is there any other workaround? I am thinking about writing the test code as unit/widget test first and just port it into integration tests once the execution is correct.

Christopher
  • 9,682
  • 7
  • 47
  • 76

1 Answers1

13

Almost.

It is partly possible with the integration_test package.

With the run command you can at least Hot Restart - which saves a lot of time when writing the tests. You are able to make changes to both your project and your test code and have the changes reflected.

From terminal execute:

flutter run integration_test/tests/your_test.dart

You should then be able to Hot Restart (with terminal focused) by pressing SHIFT + r.

It is also possible to add the test file you want to test to your IDEs run configuration and run or DEBUG it from there like a "normal" project.

Example bogus "your_test.dart" test:

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized(); 
  testWidgets('Test test testing', (WidgetTester tester) async {
    expect(true, isTrue);
  });
}
ninnepinne
  • 351
  • 3
  • 9
  • This is also working with the now integrated version of https://github.com/flutter/flutter/tree/master/packages/integration_test – Bob Jul 15 '21 at 08:22
  • I know the question is old, but I just stumbled upon this. Could someone explain why the flutter docs tell you to use `chromedriver`? Running with `flutter run path/to/test` is indeed much faster, and allows for reloading without closing test window which is a HUGE time gain. – Emile Haas Jun 06 '22 at 08:14