Questions tagged [flutter-mockito]
19 questions
7
votes
1 answer
How to mock VideoPlayerController.network() in Flutter
I'm writing a simple test for my video player widget that uses the video_player plugin. I'm not able to mock the network request made by the video controller for fetching the video over network.
My widget code looks like:
late VideoPlayerController…

Rahul Dole
- 2,723
- 2
- 24
- 30
4
votes
1 answer
Missing stub error on mockito in flutter. Trying to use setString on mocked SharedPreferences
I'm trying to mock sharedPreferences using Mockito in my flutter project. Here is the error log.
package:mockito/src/mock.dart 190:7 …

Naufal Rajabi
- 334
- 4
- 13
4
votes
0 answers
Accessing GetXController in a Flutter widget test
I am in the process of implementing a widget test for a login screen. In the app, the login screen offers the user a switch control to set preferences for biometrics if they are available on the device.
We are researching GetX and need to test this…

Pheepster
- 6,045
- 6
- 41
- 75
3
votes
0 answers
Firebase Flutter unit testing Firebase.initializeApp()
It's my first time testing an app I tried to test firebase auth and had this error
I also search in the doc but everything is outdated or doesn't implement firebase
This is my code
import 'package:ecommerce/main.dart';
import…

ABD JALIL Danane
- 41
- 1
- 3
3
votes
1 answer
Mockito not generating mocks
I had some existing mocks with mockito. I changed the names of some classes that had been mocked and now mockito doesn't generate mocks for them anymore.
An example is:
import 'package:mockito/annotations.dart';
import…

BeniaminoBaggins
- 11,202
- 41
- 152
- 287
2
votes
1 answer
type 'Null' is not a subtype of type 'Future'
I'm getting the below error while I'm trying to implement bloc testing in my flutter project
type 'Null' is not a subtype of type 'Future'
package:mynovatium/features/signup/repositories/signup_repository.dart 10:16 …

Nik
- 187
- 3
- 17
2
votes
0 answers
How to mock the flutter universal html package
I am using this library to use the html.window.open() method in my code, but I'm not able to mock it for my tests. I have imported the lib like this import "package:universal_html/html.dart" as html; in the code. My test tries to verify (using…

Rahul Dole
- 2,723
- 2
- 24
- 30
1
vote
0 answers
Get the SendPort of a named ReceivePort without direct access to the ReceivePort for testing?
I am unit testing and trying to mock a class calling C functions through ffi.
A pair of functions is responsible for starting and stopping a thread in C.
The start function passes a nativePort to C to communicate with the thread.
The stop function…

fdollack
- 31
- 4
1
vote
0 answers
Flutter: Mock extension method using Mocktail (from EasyLocalization)
The flutter package easy_localization has an extention method on the BuildContext which looks like this:
Locale get deviceLocale => EasyLocalization.of(this)!.deviceLocale;
I wish to mock this using Mocktail.
I tried:
import…

Rudy
- 437
- 2
- 7
1
vote
3 answers
'Null' is not a subtype of type 'Stream' in type cast cubit(Bloc) flutter
I have created a cubit testing project in flutter which is working fine, but when I am writing a UI test case with mockito for the same it is throwing the following error.
'Null' is not a subtype of type 'Stream' in typecast. If the real object is…

Anand Kumar Jha
- 614
- 9
- 23
1
vote
1 answer
Why does my mockito failed test when actual result same as the expected result? flutter
I'm using Mockito in flutter application and want to add some test cases:
this run failed while the actual result is the same as expected result, here's my test file:
@GenerateMocks([ResumeParserDataSource])
void main() {
late…

patriece
- 25
- 4
0
votes
0 answers
How to fix type 'Null' is not a subtype of type 'int'? (Mockito Unit test)
The error message you're encountering, "type 'Null' is not a subtype of type 'int'," suggests that there might be an issue with the way you are creating or using the MockCalculator instance in my test.
How to fix type 'Null' is not a subtype of type…

Bolt UIX
- 5,988
- 6
- 31
- 58
0
votes
0 answers
How to write widget test for screen which uses provider using mocktail or mockito?
how write widget tests using mocktail or mockito for a screen that calls an API from a provider in the initState ?
the below screen calls an api from provider in initState. so here i want to write test cases
to check the screen state such as empty,…

Shubham Hande
- 73
- 6
0
votes
2 answers
type 'Null' is not a subtype of type 'Future>'
I was learning how to do test drive development (tdd) as well as clean code architecture on flutter and I kept getting into unfamiliar problem again and again. That is - type 'Null' is not a subtype of type 'Future>'.…

Douo
- 43
- 2
- 7
0
votes
1 answer
Why do I get `MissingStubError` even though the function is stubbed?
I have this function:
Future run(
void Function() onStart,
void Function() newCallback,
void Function() updateCallback,
void Function() onFinish,
) {
return Future(() async {
// heavy work
});
}
I am trying to mock it…

fdollack
- 31
- 4