Skip to content

follow documentation for patrol #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# This is a generated file; do not edit or check into version control.
integration_test=/opt/homebrew/Caskroom/flutter/2.5.3/flutter/packages/integration_test/
patrol=/Users/smalugu/.pub-cache/git/patrol-168113aeb798d3528e296d3bc9785df3778c51ba/packages/patrol/
8 changes: 5 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ android {

defaultConfig {
applicationId "com.malugu.housestats"
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
multiDexEnabled true
}

buildTypes {
release {
Expand All @@ -65,8 +66,9 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.multidex:multidex:2.0.1"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to add it for multidex


testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'

androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package com.example.house_stats;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.integration_test.FlutterTestRunner;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import pl.leancode.patrol.ContractsExtensionsKt;
import pl.leancode.patrol.Logger;
import pl.leancode.patrol.PatrolJUnitRunner;

@RunWith(FlutterTestRunner.class)
import java.util.Arrays;

import static pl.leancode.patrol.contracts.Contracts.DartTestGroup;

@RunWith(Parameterized.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, true, false);
@Parameters(name = "{0}")
public static Object[] testCases() {
DartTestGroup dartTestGroup = PatrolJUnitRunner.setUp();

Object[] dartTestFiles = ContractsExtensionsKt.listFlatDartFiles(dartTestGroup).toArray();
Logger.INSTANCE.i("MainActivityTest.testCases(): Got Dart test files: " + Arrays.toString(dartTestFiles));
return dartTestFiles;
}

public MainActivityTest(String dartTestName) {
this.dartTestName = dartTestName;
}

private final String dartTestName;

@Test
public void runDartTest() {
Logger.INSTANCE.i("MainActivityTest.runDartTest(): " + dartTestName);

// Run a test and wait for it to finish. Throws AssertionError if the test fails.
PatrolJUnitRunner.runDartTest(dartTestName);
}
}
22 changes: 22 additions & 0 deletions integration_test/house_mocked_integration2_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:house_stats/main.dart';
import 'package:patrol/patrol.dart';

main() {
patrolTest(
'house place widget shows red color for first place',
($) async {
await $.pumpWidgetAndSettle(
const HouseStatsApp(),
);

expect($('1house'), findsOneWidget);
expect($('10'), findsOneWidget);
await $('1house').tap();

expect($('House details'), findsOneWidget);
expect($('1house'), findsOneWidget);
},
nativeAutomation: true,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order has to be this way, otherwise it won't compile. Perhaps you are using a different version of dart for your example projects?

image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because you're using Dart older than 2.17.

https://dart.dev/guides/language/evolution#dart-217

Dart 2.17 removed some restrictions on named arguments. Named arguments can now be freely interleaved with positional arguments.

);
}
27 changes: 15 additions & 12 deletions integration_test/house_mocked_integration_test.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:house_stats/main.dart';
import 'package:integration_test/integration_test.dart';
import 'package:patrol/patrol.dart';

main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Integration testing house dashboard', (tester) async {
await tester.pumpWidget(const HouseStatsApp());
await tester.pumpAndSettle();
patrolTest(
'house place widget shows red color for first place',
($) async {
await $.pumpWidgetAndSettle(
const HouseStatsApp(),
);

expect(find.text('1house'), findsOneWidget);
expect(find.text('10'), findsOneWidget);
await tester.tap(find.text('1house'));
await tester.pumpAndSettle();
expect($('1house'), findsOneWidget);
expect($('10'), findsOneWidget);
await $('1house').tap();

expect(find.text('House details'), findsOneWidget);
expect(find.text('1house'), findsOneWidget);
});
expect($('House details'), findsOneWidget);
expect($('1house'), findsOneWidget);
},
nativeAutomation: true,
);
}
4 changes: 3 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -200,6 +200,7 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -236,6 +237,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
16 changes: 15 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ version: 1.0.0+1

environment:
sdk: ">=2.15.1 <3.0.0"
flutter: '>=3.7.0'



# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down Expand Up @@ -51,7 +54,18 @@ dev_dependencies:
flutter_lints: ^1.0.0
mockito: ^5.2.0
build_runner: ^2.1.11
very_good_test_runner: ^0.1.2
patrol:
git:
url: https://github.com/leancodepl/patrol
path: packages/patrol
ref: develop

patrol:
app_name: house_stats
android:
package_name: com.example.house_stats
ios:
bundle_id: com.example.house_stats
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

Expand Down