Skip to content

Commit

Permalink
feat: add patrol test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dee committed Jun 3, 2024
1 parent 8e17751 commit 85ee45b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 11 deletions.
11 changes: 10 additions & 1 deletion catalyst_voices/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -108,6 +110,10 @@ android {
signingConfig signingConfigs.debug
}
}
testOptions {
execution "ANDROIDX_TEST_ORCHESTRATOR"
}

}

flutter {
Expand All @@ -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"

}
Original file line number Diff line number Diff line change
@@ -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<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, true, false);
}

@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);
}
}
35 changes: 35 additions & 0 deletions catalyst_voices/integration_test/common.dart
Original file line number Diff line number Diff line change
@@ -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<void> createApp(PatrolIntegrationTester $) async {
await app.main();
await $.pumpWidgetAndSettle(const App());
}

void patrol(
String description,
Future<void> Function(PatrolIntegrationTester) callback, {
bool? skip,
NativeAutomatorConfig? nativeAutomatorConfig,
LiveTestWidgetsFlutterBindingFramePolicy framePolicy =
LiveTestWidgetsFlutterBindingFramePolicy.fadePointers,
}) {
patrolTest(
description,
nativeAutomatorConfig: nativeAutomatorConfig ?? _nativeAutomatorConfig,
framePolicy: framePolicy,
skip: skip,
callback,
);
}
15 changes: 15 additions & 0 deletions catalyst_voices/integration_test/example_test.dart
Original file line number Diff line number Diff line change
@@ -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<void>.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);
});
}
12 changes: 10 additions & 2 deletions catalyst_voices/lib/configs/main_qa.dart
Original file line number Diff line number Diff line change
@@ -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<void> main() async {
GoRouter.optionURLReflectsImperativeAPIs = true;
setPathUrlStrategy();
Bloc.observer = AppBlocObserver();

// await bootstrap(() => const App());
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.18.1
intl: ^0.19.0

dev_dependencies:
flutter_test:
Expand Down
7 changes: 7 additions & 0 deletions catalyst_voices/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85ee45b

Please sign in to comment.