Questions tagged [dart-test]
29 questions
4
votes
1 answer
Flutter/Dart slow unit tests: each file taking >4s to start running
My one test file with 7 empty tests is taking 5+ seconds to start running. I've used both flutter test and the Dart test runner in VS Code, and they both take about the same amount of time.
My whole test suite of ~150 tests takes over 30 seconds to…

daddy7860
- 313
- 1
- 9
2
votes
0 answers
How can flutter test frame work be used to test Clipboard?
How can I test code that uses Clipboard in Dart. It will not work from the test framework.
The code works well when run from a main programme (after runApp(..)). But the following test fails
This is the code I want to test:
Future setText(String…

Worik
- 152
- 1
- 8
2
votes
1 answer
Dart Testing with Riverpod StateNotifierProvider and AsyncValue as state
This is my first app with Dart/Flutter/Riverpod, so any advice or comment about the code is welcome.
I'm using Hive as embedded db so the initial value for the provider's state is loaded asynchronously and using an AsyncValue of riverpod to wrapped…

Roberto
- 8,586
- 3
- 42
- 53
2
votes
2 answers
How to do never finishing Futures in Dart/Flutter?
Imagine the following scenario: A widget shows a "Loading" screen until an async callback completes, then it switches to a different widget.
I'm trying to test it, specifically the part that shows the "Loading" screen. So what I tried to do was mock…

Fabis
- 1,932
- 2
- 20
- 37
2
votes
1 answer
How can test if data has been written into a json successfully in Flutter and Dart?
I want to write a test for a user_data dart file. I want to check if data has been successfully written into the json file through an effective test.
@JsonSerializable()
class UserData {
UserData({
this.id,
this.createdAt,
…

Annie Box
- 31
- 3
2
votes
1 answer
Write a test for reading and writing files in dart
I am learning Flutter and Dart currently. Now I want to read and write files to memory. I have code for reading and writing. Now I want tests for that. Here is where I run into problems. I always…

El_Loco
- 1,716
- 4
- 20
- 35
1
vote
1 answer
How to add user input in dart test?
I'm new to dart and trying out testing. My first programm is a command line tool that takes user input. How can I simulate that during testing?
My function lets the user choose an item out of a list. I'd like to write tests if the function…

JasonTS
- 2,479
- 4
- 32
- 48
1
vote
1 answer
What is the difference between `true` and `isTrue` or `false` and `isFalse` in dart test?
I already know using the isTrue and isFalse matchers can make test assertions more descriptive and easier to read. However, I want to know if there are any other benefits or reasons for using them instead of boolean values.
expect(actual,…

Hamed
- 5,867
- 4
- 32
- 56
1
vote
1 answer
Is test order deterministic when running Flutter tests?
I have an integration test file with 3 test cases. I want to be sure that the third test case is always executed last (otherwise other test cases will fail) – how can I accomplish this?
Are the test cases always executed in the order in which…

Bartek Pacia
- 1,085
- 3
- 15
- 37
1
vote
1 answer
Is there a way to initialize for all my unit tests suite in Flutter/Dart executing a function?
The idea is to execute a common initialization for all unit tests in the suite, I mean, like executing a setupAll() before any test (that are written already) . Then I'd have an external component like setupInitializers() that is a global function…

Carlos Daniel
- 2,459
- 25
- 30
1
vote
2 answers
Assert all the items emitted by a Stream in order until it is canceled in Dart?
Is there any convenient way to assert all the items emitted by a Stream in order until it is canceled?
If I use:
expectLater(
stream,
emitsInOrder([
'item1',
'item2',
]),
);
and the Stream emits ['item1', 'item2', 'item3'] ,…

David Miguel
- 12,154
- 3
- 66
- 68
1
vote
1 answer
How to change expect text in dart test
Is there a possibility to change the text that is printed if a dart expect fails?
It works fine with primitives but working with lists of objects makes it really hard to find the difference.
UPDATE
Testing library uses toString() method to display…

Code Spirit
- 3,992
- 4
- 23
- 34
1
vote
1 answer
how can i import main functin of another dart file
How can I verify that a print is called for in dart unit tests?
I am writing a sample code for textbooks and want to try it out. There are many examples that use printing for simplicity. I want to run my unit tests to make sure the print is called…

OlimjonSN
- 45
- 4
0
votes
0 answers
How to create a matcher that verifies an async callback is doing right thing?
I would like to create a matcher that takes async or non-async callback, sets up some listeners, invokes callback, verifies listeners received expected events, and then clean up listeners.
However, I see couple blockers:
The method Matcher.matches…

polina-c
- 6,245
- 5
- 25
- 36
0
votes
0 answers
Flutter Integration tests works unexpectedly
Hello currently we are working on a big project with my teammates. And we are having issues with automating our testing.
We are building integration tests, but for whatever reason tests sometimes work and sometimes get stuck, it just gets stuck when…

Umut Arpat
- 454
- 1
- 6
- 18