3
[Edit]
If your tests are grouped in several paths and folders you must leave them inside the directory test
of the project and all files must have the suffix _test.dart
.
With this configuration done you can go to the terminal and simply apply the command related to the project thus making all the programmed tests run:
Flutter Project
flutter test
Project Dart
pub run test
In addition, there is the possibility that you group your tests together and so run all present there at once.
Example
File: test/widget_test.Dart
import 'package:flutter_test/flutter_test.dart';
void main() {
group('Counter', () {
test('value should start at 0', () {
expect(Counter().value, 0);
});
test('value should be incremented', () {
final counter = Counter();
counter.increment();
expect(counter.value, 1);
});
test('value should be decremented', () {
final counter = Counter();
counter.decrement();
expect(counter.value, -1);
});
});
group('Counter 2', () {
test('value should start at 0', () {
expect(Counter().value, 0);
});
test('value should be incremented', () {
final counter = Counter();
counter.increment();
expect(counter.value, 1);
});
test('value should be decremented', () {
final counter = Counter();
counter.decrement();
expect(counter.value, -1);
});
});
}
class Counter {
int value = 0;
void increment() => value++;
void decrement() => value--;
}
To run the tests you can do the following ways:
- Click on
Run
of the desired group; - Click on the tab
Debug
ofVSCode
and start the process there (Obs: only Vscode is used for development); - Go to the terminal and run the command
flutter test test/widget_test.dart
;
For more details see the documentation:
It can even resolve to single file but in my case are several separate files in several folders.
– rubStackOverflow
@rubStackOverflow I edited the answer adding the scenario described in your comment. If I understand correctly what you are looking for I think it will solve your problem.
– Leonardo Paim