I tried to migrate my old flutter driver tests to the new integration_test package. I copied nearly everything from the example project and executed the integration tests of the example project locally. That worked as expected, I was able to see the app UI. But my own app just shows "Test starting..." in a purple color after the splash screen was shown.
example_test.dart:
void main() {
group('My-App', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
testWidgets('Tap on SkipAuthentication', (tester) async {
app.main();
await binding.traceAction(() async {
await tester.pumpAndSettle();
await Future.delayed(Duration(seconds: 5));
final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
await tester.tap(fab);
await tester.pumpAndSettle();
});
});
integration_driver.dart:
Future<void> main() async {
integrationDriver();
}
I figured out, that if I don't start the tester.pumpWidget() shows the Widget, that I pass to the method, but thats a WidgetTest and not an integration Test.
My guess is, that it's due to the fact that my main function is an async function. I also needed this workaround in my old flutter driver tests to wait for the first frame. But I couldn't figure out how to implement that with the new integration_test package.
Hope you can help me.
Integration tests ensure that an app's components function correctly at a level that includes the app's supporting infrastructure, such as the database, file system, and network. ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.
A widget test verifies the behavior of Flutter widgets without running the app itself. An integration test (also called end-to-end testing or GUI testing) runs the full app.
Because the Microsoft.AspNetCore.Mvc.Testing package is used to configure the test host and test server, the TestHost and TestServer packages don't require direct package references in the test app's project file or developer configuration in the test app.
One of the major advancements of the integration_test plugin is the ability to run your Flutter apps targeting Android and iOS on Firebase Test Lab, giving you the ability to test across hundreds of devices simultaneously in order to find platform, form factor, or device-specific issues before shipping your app.
Huh. I started converting my flutter_driver
tests over the holidays and ran into the same thing.
My fix was to add a fixed sleep after launching the test, which allowed it to initialize properly. So one test case looks like this:
testWidgets("Main screen loads", (WidgetTester widgetTester) async {
app.main();
await sleep(Duration(seconds: 10));
await widgetTester.pumpAndSettle();
expect(find.text("What are you looking for?"), findsOneWidget);
});
I had this issue also and the sleep
/ Future.delayed
did not work. Some times the integration tests were run but mostly they were not.
What ultimately fixed the issue for me was to change the framePolicy
of IntegrationTestWidgetsFlutterBinding
to LiveTestWidgetsFlutterBindingFramePolicy.fullyLive
. Here is a full example:
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
as IntegrationTestWidgetsFlutterBinding;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
testWidgets("failing test example", (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
// Start testing here...
});
}
The solution was found from Google Codelabs.
I was struggling with this also for some hours and finally found the answer.
Your issue is that do not pump a widget with await tester.pumpWidget(MyApp())
Your test look like:
void main() {
testWidgets('Tap on SkipAuthentication', (tester) async {
app.main(); // <--- You call app.main() - This Flutter Driver style, but not integration test style
await binding.traceAction(() async {
await tester.pumpAndSettle();
await Future.delayed(Duration(seconds: 5));
final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
await tester.tap(fab);
await tester.pumpAndSettle();
});
});
You need to change your test like this:
void main() {
testWidgets('Tap on SkipAuthentication', (tester) async {
await tester.pumpWidget(MyApp()); // You need to call await tester.pumpWidget();
await tester.pump(const Duration(seconds: 1));
final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
await tester.tap(fab);
await tester.pump();
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With