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
86
votes
12 answers

Widget test fails with No MediaQuery widget found

My question is about flutter widget test, what is proper way to test existing widgets wrapped new Scaffold(...)? I have found MediaQuery.of but it accepts BuildContext instead of Widget. Details: I have wrote simple login form widget and trying to…
Zufar Muhamadeev
  • 3,085
  • 5
  • 23
  • 51
71
votes
7 answers

Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'

I have just started using Flutter and i'm having this problem while running my code "Another exception was thrown: type 'MyApp' is not a subtype of type 'StatelessWidget'". And the interesting part is that i dont even have this 'StatelessWidget' in…
Leonardo
  • 733
  • 1
  • 6
  • 7
60
votes
11 answers

Because every version of flutter_test from sdk depends on... flutter_test from sdk is forbidden, version solving failed

I'm having this issue when I've added http dependency in my flutter project. Can anyone please help me with it?
Shoaib Nomani
  • 601
  • 1
  • 5
  • 4
59
votes
18 answers

Flutter : Target file "lib/main.dart" not found

When I perform a flutter run I get an error Target file "lib/main.dart" not found. Why is this happening and how can I fix this ?
Keshav Aditya R P
  • 3,001
  • 5
  • 21
  • 28
55
votes
12 answers

How to solve Not found: 'dart:ui' error while running integration tests on Flutter

I have an app, it is very simple and have just one widget. It is working fine, however when I run integration test by calling: $ flutter drive --target=test_driver/app.dart I get the following error: …
RobertoAllende
  • 8,744
  • 4
  • 30
  • 49
54
votes
20 answers

How to solve "Unable to find git in your PATH" on Flutter?

I've just tried to install Flutter on Linux and when I try to run a flutter command (flutter doctor), I'm getting Error: Unable to find git in your PATH. How can I solve this?
Nikolay Shindarov
  • 1,616
  • 2
  • 18
  • 25
47
votes
10 answers

Dart/Flutter Web unit testing errors: Error: Not found: 'dart:html'

I'm working on a Flutter web app and I'm having trouble running a test. Flutter 1.7.8+hotfix.4 • channel stable • git@github.com:flutter/flutter.git Framework • revision 20e59316b8 (9 weeks ago) • 2019-07-18 20:04:33 -0700 Engine • revision…
skillit zimberg
  • 1,024
  • 1
  • 14
  • 22
46
votes
6 answers

Flutter: Test that a specific exception is thrown

in short, throwsA(anything) does not suffice for me while unit testing in dart. How to I test for a specific error message or type? Here is the error I would like to catch: class MyCustErr implements Exception { String term; String errMsg() =>…
xpeldev
  • 1,812
  • 2
  • 12
  • 23
46
votes
3 answers

How to test code that uses DateTime.now in Flutter?

I have this class: import 'package:flutter/material.dart'; class AgeText extends StatelessWidget { final String dateOfBirth; const AgeText({Key key, @required this.dateOfBirth}) : super(key: key); @override Widget build(BuildContext…
Jordan Davies
  • 9,925
  • 6
  • 40
  • 51
42
votes
8 answers

How to test Flutter widgets on different screen sizes?

I have a Flutter widget which shows extra data depending on the screen size. Does anyone know a way of testing this widget on multiple different screen sizes? I've had a look through the widget_tester source code but can't find anything.
Jordan Davies
  • 9,925
  • 6
  • 40
  • 51
42
votes
6 answers

How to test navigation via Navigator in Flutter

Let's say, I have a test for a screen in Flutter using WidgetTester. There is a button, which executes a navigation via Navigator. I would like to test behavior of that button. Widget/Screen class MyScreen extends StatefulWidget { MyScreen({Key…
Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42
41
votes
7 answers

How to Make Two Floating Action Button in Flutter?

Created counter app with one floating action button. If i want to add one more button for reset the counter, where can i add second floating action button at bottom bar? Also i have to add any method in void section or is there any reset counter…
fluttertalk
  • 499
  • 1
  • 6
  • 13
41
votes
3 answers

Is it possible to access children/parent widgets from a given widget, in a Flutter test?

I'm writing unit and integration tests for Flutter. Is it possible to access children/parent widgets from a given widget?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
35
votes
4 answers

Bad state: Mock method was not called within `when()`. Was a real method called?

I'm trying to make a mock of an httpRequest in flutter using mockito. Here I define a global http client: library utgard.globals; import 'package:http/http.dart' as http; http.Client httpClient = http.Client(); Then I replace in integration…
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
33
votes
5 answers

After migrating flutter code to null-safety, mock objects not accepting `any`

After the release of Flutter 2, I've migrated my code to sdk: '>=2.12.0 <3.0.0' and all codes are "sound null safety" now. But I encountered errors in unit tests with mockito…
Arash
  • 825
  • 2
  • 11
  • 19
1
2 3
99 100