Reputation: 9
I have multiple test-classes under folder "integration-test" (e.g. "class1_test.dart", "class2_test.dart"...); I found scripts to generate app-apk and test-apk and run on Firebase TestLab, but these scripts generate test-app for particular test-class, but I would like to run all my tests at once, not only from particular class. How can I do that?
pushd android
flutter build apk
./gradlew app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=integration_test/class1_test.dart #generates apk for 1class
popd
gcloud firebase test android run \
--type instrumentation \
--app build/app/outputs/apk/debug/app-debug.apk \
--test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk
Tried to specified few --Ptarget arguments for ./gradlew app:assembleDebug, but anyway it generates test-app with tests only in class1
Upvotes: 1
Views: 1037
Reputation: 94
It is pretty simple to execute many test classes together to execute in firebase test lab:
Ex: Lets say below two test classes
class1_test.dart
void main() {
group('Test1', () {
testWidgets('Test case 1', (WidgetTester tester) async {
// Your test logic here
});
});
}
class2_test.dart
void main() {
group('Test2', () {
testWidgets('Test case 2', (WidgetTester tester) async {
// Your test logic here
});
});
}
Now make a single test suite class in which you initialize the test binding and call main methods of above two classes
test_suite.dart file
import '../class1_test.dart' as testclass1;
import '../class2_test.dart' as testclass2;
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
//executing all tests
testclass1.main();
testclass2.main();
}
How to call in test app assemble to run in firebase test lab:
./gradlew app:assembleDebug -Ptarget=integration_test/test_suite.dart #generates apk for 1class
popd
This way all of your test cases will run from a single test suite file, if you want to add more test classess , you can add in test suite file in similar way. I hope it works for you
Cheers
Upvotes: 0
Reputation: 141
To run multiple integration tests in the same APK, you can follow these steps:
integration_test/test1.dart
integration_test/test2.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Test1', () {
testWidgets('Test case 1', (WidgetTester tester) async {
// Your test logic here
});
testWidgets('Test case 2', (WidgetTester tester) async {
// Your test logic here
});
});
}
integration_test.dart
file. This file will be responsible for running all your test files:import 'package:integration_test/integration_test_driver.dart';
import '../integration_test/test1.dart' as test1;
import '../integration_test/test2.dart' as test2;
Future<void> main() async {
await integrationDriver(test1.main);
await integrationDriver(test2.main);
}
dev_dependencies:
dependencies:
integration_test:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
import 'package:flutter_driver/driver_extension.dart';
import 'package:your_app/main.dart' as app;
void main() {
enableFlutterDriverExtension();
app.main();
}
pubspec.yaml
under dev_dependencies
:flutter_driver:
sdk: flutter
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app.dart
This command will run all the test files you've specified in the integration_test.dart
file in the test_driver directory. The output will show the results of each test case from all test classes.
Upvotes: 0