diff --git a/catalyst_voices/android/app/build.gradle b/catalyst_voices/android/app/build.gradle index 6d581a2d3b..993c22b8f7 100644 --- a/catalyst_voices/android/app/build.gradle +++ b/catalyst_voices/android/app/build.gradle @@ -53,7 +53,9 @@ android { targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner" + testInstrumentationRunnerArguments clearPackageData: "true" + multiDexEnabled true } signingConfigs { @@ -108,6 +110,10 @@ android { signingConfig signingConfigs.debug } } + testOptions { + execution "ANDROIDX_TEST_ORCHESTRATOR" + } + } flutter { @@ -116,7 +122,10 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:multidex:2.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.3' + androidTestUtil "androidx.test:orchestrator:1.4.2" + } diff --git a/catalyst_voices/android/app/src/androidTest/java/androidTest/java/io/projectcatalyst/catalyst_voices/MainActivityTest.java b/catalyst_voices/android/app/src/androidTest/java/androidTest/java/io/projectcatalyst/catalyst_voices/MainActivityTest.java index 15b7a2b273..443b036d92 100644 --- a/catalyst_voices/android/app/src/androidTest/java/androidTest/java/io/projectcatalyst/catalyst_voices/MainActivityTest.java +++ b/catalyst_voices/android/app/src/androidTest/java/androidTest/java/io/projectcatalyst/catalyst_voices/MainActivityTest.java @@ -1,12 +1,32 @@ package io.projectcatalyst.catalyst_voices; -import androidx.test.rule.ActivityTestRule; -import dev.flutter.plugins.integration_test.FlutterTestRunner; -import org.junit.Rule; +import androidx.test.platform.app.InstrumentationRegistry; +import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import pl.leancode.patrol.PatrolJUnitRunner; -@RunWith(FlutterTestRunner.class) +@RunWith(Parameterized.class) public class MainActivityTest { - @Rule - public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class, true, false); -} \ No newline at end of file + + @Parameters(name = "{0}") + public static Object[] testCases() { + PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation(); + instrumentation.setUp(MainActivity.class); + instrumentation.waitForPatrolAppService(); + return instrumentation.listDartTests(); + } + + public MainActivityTest(String dartTestName) { + this.dartTestName = dartTestName; + } + + private final String dartTestName; + + @Test + public void runDartTest() { + PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation(); + instrumentation.runDartTest(dartTestName); + } +} diff --git a/catalyst_voices/integration_test/common.dart b/catalyst_voices/integration_test/common.dart new file mode 100644 index 0000000000..c0e7586339 --- /dev/null +++ b/catalyst_voices/integration_test/common.dart @@ -0,0 +1,35 @@ +import 'package:catalyst_voices/app/app.dart'; +import 'package:catalyst_voices/app/view/app_page.dart'; +import 'package:catalyst_voices/configs/main_qa.dart' as app; +import 'package:flutter_test/flutter_test.dart'; +import 'package:patrol/patrol.dart'; + +export 'package:flutter_test/flutter_test.dart'; +export 'package:patrol/patrol.dart'; + +const _nativeAutomatorConfig = NativeAutomatorConfig( + findTimeout: Duration(seconds: 30), // 10 seconds is too short for some CIs +); +const _patrolTesterConfig = PatrolTesterConfig(); + +Future createApp(PatrolIntegrationTester $) async { + await app.main(); + await $.pumpWidgetAndSettle(const App()); +} + +void patrol( + String description, + Future Function(PatrolIntegrationTester) callback, { + bool? skip, + NativeAutomatorConfig? nativeAutomatorConfig, + LiveTestWidgetsFlutterBindingFramePolicy framePolicy = + LiveTestWidgetsFlutterBindingFramePolicy.fadePointers, +}) { + patrolTest( + description, + nativeAutomatorConfig: nativeAutomatorConfig ?? _nativeAutomatorConfig, + framePolicy: framePolicy, + skip: skip, + callback, + ); +} diff --git a/catalyst_voices/integration_test/example_test.dart b/catalyst_voices/integration_test/example_test.dart new file mode 100644 index 0000000000..dc0e6728f8 --- /dev/null +++ b/catalyst_voices/integration_test/example_test.dart @@ -0,0 +1,15 @@ +import 'common.dart'; + +void main() { + patrol('Test Landing page', (PatrolIntegrationTester $) async { + // await app.main(); + // await $.pumpWidgetAndSettle(const App()); + await createApp($); + await Future.delayed(const Duration(seconds: 15)); + expect( + $("Project Catalyst is the world's largest decentralized innovation engine for solving real-world challenges."), + findsOneWidget, + ); + expect($('Coming'), findsOneWidget); + }); +} diff --git a/catalyst_voices/lib/configs/main_qa.dart b/catalyst_voices/lib/configs/main_qa.dart index b169becdb6..6984727519 100644 --- a/catalyst_voices/lib/configs/main_qa.dart +++ b/catalyst_voices/lib/configs/main_qa.dart @@ -1,6 +1,14 @@ import 'package:catalyst_voices/app/app.dart'; +import 'package:catalyst_voices/configs/app_bloc_observer.dart'; import 'package:catalyst_voices/configs/bootstrap.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; +import 'package:url_strategy/url_strategy.dart'; -void main() async { - await bootstrap(() => const App()); +Future main() async { + GoRouter.optionURLReflectsImperativeAPIs = true; + setPathUrlStrategy(); + Bloc.observer = AppBlocObserver(); + + // await bootstrap(() => const App()); } diff --git a/catalyst_voices/packages/catalyst_voices_localization/pubspec.yaml b/catalyst_voices/packages/catalyst_voices_localization/pubspec.yaml index 2e5dafb8a4..c00aa6f156 100644 --- a/catalyst_voices/packages/catalyst_voices_localization/pubspec.yaml +++ b/catalyst_voices/packages/catalyst_voices_localization/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter - intl: ^0.18.1 + intl: ^0.19.0 dev_dependencies: flutter_test: diff --git a/catalyst_voices/pubspec.yaml b/catalyst_voices/pubspec.yaml index 810aaed179..f63a04040e 100644 --- a/catalyst_voices/pubspec.yaml +++ b/catalyst_voices/pubspec.yaml @@ -56,7 +56,14 @@ dev_dependencies: sdk: flutter mockito: ^5.4.4 mocktail: ^1.0.1 + patrol: ^3.6.1 flutter: uses-material-design: true generate: true + +patrol: + app_name: Catalyst Voices + flavor: qa + android: + package_name: io.projectcatalyst.catalyst_voices