Questions tagged [flutter-test]

Flutter-Test contains tests related to Flutter app including Unit tests, Widget test and end-to-end integration tests using Flutter-Driver.

Flutter officially highlights 3 different types of testing as mentioned here: https://flutter.dev/docs/testing

Unit tests: A unit test tests a single function, method, or class.

Widget tests: A widget test (in other UI frameworks referred to as component test) tests a single widget.

Integration tests: An integration test tests a complete app or a large part of an app.

1961 questions
12
votes
2 answers

Mockito - stub a method after the null-safety migration

Before the null safety I could simply mock up the sendRequest(...) method like that: void stubBaseRepositorySendRequestResponse(String response) { when(baseRepository.sendRequest(onGetData: anyNamed('onGetData'))) .thenAnswer((_) { …
Pablito
  • 521
  • 4
  • 15
12
votes
1 answer

MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) on tests

we are using the new version of FlutterFire, but we have some issues when running our tests, we managed to initialise Firebase adding this: setUp(() async { TestWidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); …
chsanch
  • 121
  • 4
12
votes
2 answers

developer.log does not print log in the test

I use log from import 'dart:developer'; but it seems that it does not print anything when I use from unit test. What should I use for logging in both test and dev environments but not in production? Thanks.
mmdc
  • 1,677
  • 3
  • 20
  • 32
12
votes
2 answers

Unit Testing for Providers in Flutter

We have started a new project on Flutter in the TDD approach. I am using providers for State Management. While trying to write the Widget Testing we are facing the issue to test the providers. Can you please suggest with an example to write the unit…
12
votes
3 answers

How do I stub a function that does not belong to a class, during a widget test?

I am creating a flutter app that uses the native camera to take a photo, using the official flutter camera package (https://pub.dev/packages/camera). The app opens up a modal that loads a CameraPreview based on the the result of the availableCameras…
Bakkingamu
  • 141
  • 1
  • 4
12
votes
2 answers

How to mock navigation arguments for testing flutter screen widgets?

I would like to write a mockito test for a screen widget in flutter. The problem is, that this widget uses a variable from the navigation argument and I'm not sure how to mock this variable. This is the example screen: class TestScreen extends…
Daniel
  • 1,999
  • 4
  • 15
  • 27
12
votes
3 answers

How to open a drawer in flutter test

I am trying to test a custom drawer but find it hard opening it in the test, tried the following to begin with and even this test doesn't pass. The error is: Bad state: no element. void main() { testWidgets('my drawer test', (WidgetTester tester)…
dragonfly02
  • 3,403
  • 32
  • 55
12
votes
2 answers

Unit Testing On Flutter Firebase functions

Good day, I am trying to perform some unit testing on the below function that creates a document in Cloud Firestore. I have used a function in my app and it creates a document, but I want to write a test.dart file that performs unit testing for the…
Frank
  • 138
  • 7
12
votes
2 answers

How to fully dump / print a variable to console in Flutter?

This is a follow-up to this Dart question. Since Flutter doesn't support reflection and we can't use mirrors, how would you go about debugging, let's say an instance of firebase_database DatabaseReference ? I'm trying to write tests, and knowing…
Adrien Lemaire
  • 1,744
  • 2
  • 20
  • 29
11
votes
3 answers

how can I use flutter_test from sdk and the package test? what version of test uses test_api 0.4.3?

I am trying to run some basic unit test for my flutter app. But when I run pub get I get the following error after including test: 1.20.0 in my pubspec: dev_dependencies: dependency_validator: ^3.1.0 # run flutter pub run dependency_validator …
lost baby
  • 3,178
  • 4
  • 32
  • 53
11
votes
1 answer

Can integration_test package interact with webview?

I use integration_test package to write UI tests on Dart for iOS and Android platforms. I also have a webview in my app showing login page with text fields. I use webview_flutter for it. Does anybody know if tester can interact with my webview…
Mol0ko
  • 2,938
  • 1
  • 18
  • 45
11
votes
1 answer

How to Tap on native iOS popup to allow Notifications. (Flutter Integration Test)

Flutter Driver code has to tap on the native "Allow" button to continue and simulate the correct user behaviour. See this screenshot. Native iOS popup before app starts - Allow Notifications App has not yet completely started and is waiting for this…
randolf altman
  • 113
  • 1
  • 8
11
votes
2 answers

Cannot find Widgets in test inside of Consumer Widget of Provider

I created the following Flutter test for my widget testWidgets("", (WidgetTester tester) async { await tester.pumpWidget( ChangeNotifierProvider( create: (context) => SettingsViewProvider(), …
Max Weber
  • 1,081
  • 11
  • 21
11
votes
1 answer

Flutter webviews gives net::ERR_CACHE_MISS message

When using webview in flutter i am getting this message. here is the code import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; class Webview extends StatelessWidget { String url; …
11
votes
9 answers

How to deactivate or ignore layout overflow messages in Flutter widget tests?

Tests run with the Ahem font, which is too big, and sometimes it overflows, breaking tests. Some tests don't care about overflow anyway, so there should be a way to deactivate them. I have many tests which run OK in the simulator, but break in…
Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133