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
14
votes
6 answers

How to get the actual aspect ratio of the video?

I don't want my video to look stretched. I'm using Chewie flutter package as my video player. I tried using _controller.value.size.aspectRatio but it returns an error The getter 'aspectRatio' was called on null. here is my code to get a video from…
Gentle
  • 759
  • 2
  • 8
  • 20
14
votes
2 answers

How do I test an assertion?

I found out how you can test an exception or error: https://stackoverflow.com/a/54241438/6509751 But how do I test that the following assert works correctly? void cannotBeNull(dynamic param) { assert(param != null); } I tried the following, but…
creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
14
votes
4 answers

How to mock http request in flutter integration test?

I'm trying to do so using Mockito, this is my test: import 'package:http/http.dart' as http; import 'package:utgard/globals.dart' as globals; import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart'; import…
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
14
votes
5 answers

How to find off-screen ListView child in widget tests?

When displaying multiple children in a ListView, if a child is off-screen it can't be found by a widget test. Here's a full example: main.dart import 'package:flutter/material.dart'; void main() => runApp(App()); class App extends StatelessWidget…
Jordan Davies
  • 9,925
  • 6
  • 40
  • 51
14
votes
2 answers

Flutter: How to implement FlutterError.OnError correctly

Can someone show me how to implement overriding flutter errors during widget test so I can check for my own custom errors. I have seen snippets online mentioning this but all of my implementations fail void main() { testWidgets('throws an error…
xpeldev
  • 1,812
  • 2
  • 12
  • 23
14
votes
2 answers

Flutter: Testing for exceptions in widget tests

How do I go about making sure the ui (widget) throws an exception during widget testing in Flutter. Here is my code that does not work: expect( () => tester.tap(find.byIcon(Icons.send)), throwsA(const…
xpeldev
  • 1,812
  • 2
  • 12
  • 23
13
votes
1 answer

'!_debugInitialized': is not true while running flutter integration tests

I am trying to run a basic flutter integration test to invoke my main app widget but it's failing. I have followed the approach as described in the official docs [https://docs.flutter.dev/testing/integration-tests] Here is the complete stack…
Bhupesh Varshney
  • 1,522
  • 14
  • 19
13
votes
8 answers

Error on flutter pub run build_runner build

I am facing this issue when I run flutter pub run build_runner build. I have tried solutions like flutter clean, flutter pub-cache repair flutter pub get, etc. Dependencies like Mockito, HTTP, and build_runner are added on pubspec and flutter pub…
Hassan
  • 151
  • 1
  • 8
13
votes
3 answers

How to resolve all the sdk and dependencies issues after cloning a project that was using old sdk and packages?

I have cloned hackernews project that is being developed by google devs in their flutter boring show series on youtube. On running flutter run I am getting these errors. The current Dart SDK version is 2.9.2. …
Mateen Kiani
  • 2,869
  • 2
  • 19
  • 29
13
votes
1 answer

Finding a TextSpan to tap on with Flutter tests

With a Flutter WidgetTester how can you tap on a TextSpan, like in the code below? RichText( text: TextSpan( children: [ TextSpan(text: 'aaa '), TextSpan( text: 'bbb ', recognizer: TapGestureRecognizer() …
Benno Richters
  • 15,378
  • 14
  • 42
  • 45
13
votes
1 answer

Print out widget tree in Flutter test

In Flutter, how can I print out the current widget tree in a widget unit test, in order to understand the current state of the UI for debugging? (For example, in React/Ensyme, I could use debug(). Is there something comparable in Flutter?)
Matt R
  • 9,892
  • 10
  • 50
  • 83
13
votes
1 answer

How to stub target platform in Flutter

Suppose I have a widget that behaves differently according to the platform: If the platform is Android, it shows a RaisedButton. If the platform is iOS, it shows a CupertinoButton. Example: @override Widget build(BuildContext context) { if…
Hugo Passos
  • 7,719
  • 2
  • 35
  • 52
13
votes
3 answers

using the system back button from flutter driver

How can I use the system back button in an integration test? So I'm using flutter and am writing integration tests, in most circumstances I can use the AppBar navigation, finding it by tool tip looks like this…
13
votes
1 answer

How to hide layout overflow message in flutter

I'm new for Flutter.Working with bottom sheet.Bottom sheet has normal constant height. it's height will increase based on dragging. Please refer the code below.Issue is when the bottom sheet is normal size views are overflowed. please refer attached…
Gowsik Raja
  • 684
  • 1
  • 8
  • 22
12
votes
1 answer

How to get a BuildContext from WidgetTester?

When doing a Flutter widget test, I can get a context from the WidgetTester if I know something about at least one widget in the tree. E.g., if I know there's a Text widget in the test widget tree, I can BuildContext context =…
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52