Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot reload for Flutter integration test?

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.

like image 599
Christopher Avatar asked Dec 31 '22 15:12

Christopher


1 Answers

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);
  });
}
like image 145
ninnepinne Avatar answered Jan 02 '23 04:01

ninnepinne