无法正常运行Patrol测试



我可以使用以下代码运行integration_test:

##########
# integration_test/openapp_test.dart
##########
import 'package:myapp/main.dart' as app;
group('end-to-end test', () {
testWidgets('tap on the floating action button, verify counter',
(tester) async {
app.main(isTesting: true);
await tester.pumpAndSettle(
const Duration(seconds: 10),
);
// first screen
expect(find.text('Mulai baru'), findsOneWidget);
// I go to 'Login from Onboarding' page
await tester.tap(find.byKey(
const Key(OnboardingKey.buttonMasukKeAkun),
));
});
});
##########
# test_driver/integration_test.dart
##########
// @dart=2.9
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();

我的主。Dart看起来像这样:

##########
# lib/main.dart
##########
Future<void> main({bool isTesting = false}) async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await Firebase.initializeApp();
_initCrashlytics();

await SharedPreference.wipeSecureStorage();
runZonedGuarded<Future<void>>(
() async {
runApp(App(isTesting: isTesting));
},
(Object object, StackTrace stackTrace) {
...
...
,,,
},
);
}
class App extends StatelessWidget {
const App({Key? key, this.isTesting = false}) : super(key: key);
final bool isTesting;
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
...
...
...
}
}

命令我用来运行上面的测试(运行在android设备上):

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/openapp_test_copy.dart --flavor=staging

当我运行上面的命令时它工作得很好。脚本将apk安装到我的设备中,运行测试,并显示通过的


当我尝试使用patrolTest将其更改为以下内容时

##########
# integration_test/openapp_test.dart
##########
void main() {
group('end-to-end test', () {
patrolTest('tap on the floating action button, verify counter',
(PatrolTester $) async {
// app.main(isTesting: true);
await $.pumpWidgetAndSettle(
const App(
isTesting: true,
),
duration: const Duration(seconds: 20),
);
await $.pump(const Duration(seconds: 50));
expect(find.text('Mulai baru'), findsNothing);
});
});
}

或者这个(我尝试了两种不同的方式来启动应用程序,因为我不知道哪一个是正确的

##########
# integration_test/openapp_test.dart
##########
void main() {
group('end-to-end test', () {
patrolTest('tap on the floating action button, verify counter',
(PatrolTester $) async {
await $.pumpWidget(
const App(
isTesting: true,
),
);
await $.pumpAndSettle(
duration: const Duration(seconds: 20),
);
expect(find.text('Mulai baru'), findsNothing);
});
});
}

并尝试使用以下命令

运行它
patrol test --flavor staging

总是显示test passed..但我没有看到测试运行…它不安装应用程序,并直接声明测试通过
它应该显示失败,因为这个命令expect(find.text('Mulai baru'), findsNothing);应该失败

FileSystemException: Cannot open file, path = '/Users/thekucays/.zshrc' (OS Error: Permission denied, errno = 13)
No device specified, using the first one (P0AA003810060900077)
Every test target will be run 1 time(s)
• Building apk with entrypoint openapp_test.dart...
✓ Completed building apk with entrypoint openapp_test.dart (22.3s)
• Executing tests of apk with entrypoint openapp_test.dart on device P0AA003810060900077...
✓ Completed executing apk with entrypoint openapp_test.dart on device P0AA003810060900077 (12.2s)
PASS  openapp_test.dart on P0AA003810060900077

这里出了什么问题?我错过什么了吗?


flutter doctor -v输出

[!] Flutter (Channel stable, 3.7.1, on macOS 12.6.1 21G217 darwin-arm64, locale en-ID)
• Flutter version 3.7.1 on channel stable at /Users/thekucays/fvm/versions/3.7.1
! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/2.18.4/libexec/bin/dart, which is not inside your current Flutter SDK checkout at
/Users/thekucays/fvm/versions/3.7.1. Consider adding /Users/thekucays/fvm/versions/3.7.1/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7048ed95a5 (9 weeks ago), 2023-02-01 09:07:31 -0800
• Engine revision 800594f1f4
• Dart version 2.19.1
• DevTools version 2.20.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/thekucays/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /Users/thekucays/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13A1030d
• CocoaPods version 1.12.0
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2021.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] VS Code (version 1.73.1)
• VS Code at /Users/thekucays/Documents/Installers/Visual Studio Code.app/Contents
• Flutter extension version 3.60.0
[✓] Connected device (2 available)
• Nokia 5 3 (mobile) • P0AA003810060900077 • android-arm64 • Android 11 (API 30)
• macOS (desktop)    • macos               • darwin-arm64  • macOS 12.6.1 21G217 darwin-arm64
[✓] HTTP Host Availability
• All required HTTP hosts are available

patrol doctor输出

Patrol CLI version: 1.1.3
Program adb found in /Users/thekucays/Library/Android/sdk/platform-tools/adb
Env var $ANDROID_HOME set to /Users/thekucays/Library/Android/sdk
Program xcodebuild found in /usr/bin/xcodebuild
Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller
Program ios-deploy found in /opt/homebrew/bin/ios-deploy

patrol -V输出

patrol_cli v1.1.3

看起来这是我自己的坏lol
我终于管理它运行使用这些配置

  • integration_test.dart保持不变
  • android/app/src/my/package/name下创建MainActivityTest.java
package my.package.name
import org.junit.Rule;
import org.junit.runner.RunWith;
import pl.leancode.patrol.PatrolTestRule;
import pl.leancode.patrol.PatrolTestRunner;
@RunWith(PatrolTestRunner.class)
public class MainActivityTest {
@Rule
public PatrolTestRule<MainActivity> rule = new PatrolTestRule<>(MainActivity.class);
}
  • 在我的pubspec.yaml底部,我添加了这个
patrol:
app_name: Awesome App
android:
package_name: my.package.name
  • insideandroid/app/build.gradleindefaultConfigblock i add this
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  • and this insidedepedenciesblock
testImplementation "junit:junit:4.13.2"

并使用以下命令

运行它
patrol test --target integration_test/openapp_test.dart
然而,我不能使用

$.pumpWidgetAndSettle(foo())

启动应用程序…我在openapp_test.dart

中使用WidgetTester的默认命令
patrolTest(
'counter state is the same after going to home and switching apps',
nativeAutomation: true,
(PatrolTester $) async {
app.main();
await $.tester.pumpAndSettle(
const Duration(seconds: 10),
);
},
);

看起来$.pumpWidget()$.pumpWidgetAndSettle()之间的行为有轻微的差异(?)

最新更新