Skip to content
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

Patrol does't run tests (Total: 0) even with a minimal setup #2489

Closed
dthuesen opened this issue Jan 14, 2025 · 6 comments
Closed

Patrol does't run tests (Total: 0) even with a minimal setup #2489

dthuesen opened this issue Jan 14, 2025 · 6 comments
Assignees

Comments

@dthuesen
Copy link

Steps to reproduce

  1. reduced main.dart to the minimum to run a flutter app
  2. reduce the test file to the absolute bare minimum to run a patrol test
  3. start test in development mode on "Emulator Pixel 8 Pro" or "Pixel 4", both with API 35
  4. get this result:

No device specified, using the first one (emulator-5554)
• Building apk with entrypoint test_bundle.dart...
✓ Completed building apk with entrypoint test_bundle.dart (30.3s)
• Executing tests of apk with entrypoint test_bundle.dart on emulator-5554...
Hot Restart: logs connected
[WARN] Hot Restart: not attached to the app yet
✓ App shut down on request (13.4s)

  1. start the test in test mode with verbose flag
  2. Still doesn't run the test. Result is enclosed to the logs

Actual results

Environment

  • Patrol CLI: 3.4.1 (patrol --version)
  • Patrol Package: tried both ^3.4.1 (matching the CLI) and ^3.13.2
  • Flutter: 3.27.1
  • Dart: 3.6.0
  • Android Gradle Plugin (AGP): 7.3.0 (warns about compileSdk=33/34 but keeps building)
  • Emulator: Pixel 8 Pro (API 35) / Pixel 6 (API 33/34)
  • OS: macOS

In AndroidManifest.xml, I set:

<activity android:name="software.iva.ivaapp.MainActivity" ... />

And in MainActivityTest.java (automatically generated by Patrol), I have:

instrumentation.setUp(MainActivity.class);
instrumentation.waitForPatrolAppService();
return instrumentation.listDartTests();

The app itself launches fine with flutter run. But when running patrol test (or patrol develop), Patrol consistently reports:

Test summary:
📝 Total: 0
✅ Successful: 0
❌ Failed: 0
⏩ Skipped: 0

Gradle test execution failed with code 1

Or [WARN] Hot Restart: not attached to the app yet! in develop mode.

What I've tried

  1. Minimal main.dart
// main.dart
void main() => runApp(MaterialApp(home: Text('Hello Patrol!')));

No special initializations, no plugins.

  1. Minimal test file
// integration_test/my_test.dart
import 'package:patrol/patrol.dart';
import 'package:flutter/material.dart';

void main() {
  patrolTest(
    'App starts correctly',
    ($) async {
      await $.pumpWidgetAndSettle(
        MaterialApp(home: Text('Hello Patrol!')),
      );
    },
  );
}
  1. Cleaning & reinstalling

flutter clean, wiping emulator data, adb uninstall <package>, etc.
4. Matching Patrol versions

  • Tried patrol: ^3.4.1 (same as CLI 3.4.1)
  • Also tried patrol: ^3.13.2 + building from source for the CLI.
  1. Lowering compileSdkVersion
  • Went from 34 down to 33 to match the AGP recommendation.

No matter what, Patrol always shows “0 tests” discovered after the APK is built and installed.

Expected behavior

Patrol should at least detect 1 test and run it successfully.

Actual behavior

  • Test summary: Total: 0
  • Then Gradle test execution failed with code 1.
  • In develop mode, it warns [WARN] Hot Restart: not attached to the app yet! and shuts down immediately.

Questions

  1. Has anyone else experienced this “0 tests discovered” outcome even with a minimal Flutter setup?
  2. Are there any known incompatibilities with my environment (Flutter 3.27.1, Dart 3.6.0, AGP 7.3.0)?
  3. Any suggestions for further debugging to determine whether my instrumentation setup (MainActivityTest.java) is causing the problem or if there’s a deeper Patrol issue?

Thanks for any help! I’d be happy to provide logs or additional info if needed.

Logs

Logs verbose test
[log_from_test in_verbose_mode.txt](https://github.com/user-attachments/files/18411438/log_from_test.in_verbose_mode.txt)

Patrol version

patrol: ^3.13.2
CLI Version: patrol_cli v3.4.1

Patrol Doctor output

Patrol Doctor output
Patrol doctor:
Patrol CLI version: 3.4.1
Flutter command: flutter 
  Flutter 3.27.1 • channel stable
Android: 
• Program adb found in /Users/detlefvonderthusen/Library/Android/sdk/platform-tools/adb
• Env var $ANDROID_HOME set to /Users/detlefvonderthusen/Library/Android/sdk
iOS / macOS: 
• Program xcodebuild found in /usr/bin/xcodebuild
• Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller

Flutter Doctor output

Flutter Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.2 24C101 darwin-arm64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] Connected device (4 available)
    ! Error: Browsing on the local area network for iPad von Detlef. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

• No issues found!
@zoskar zoskar self-assigned this Jan 15, 2025
@zoskar
Copy link

zoskar commented Jan 15, 2025

Hi @dthuesen , thanks for detailed report.
The most popular causes of your issue are:

  1. MainActivity.java was not created in right directory
  2. Problems with emulator, it's worth to wipe its data
  3. Make sure you are not using emulator with API 35 (we have an open issue for it, the fix is on the way) - you listed API 35 in reproduction steps and in one of the emulators in Environment section

If the steps above do not help please also attach abd logcat logs (run in separate console before running patrol test)

@zoskar zoskar added the waiting for response Waiting for user's response label Jan 15, 2025
@dthuesen
Copy link
Author

Hi @zoskar, thank you for your very fast reply.

1.) I initially tried to use the MainActivity as it was already set up in my project:

css
Code kopieren
android/app/src/main/kotlin/software/iva/ivaapp/MainActivity.kt
According to the Patrol documentation, I put MainActivityTest.java here:

bash
Code kopieren
android/app/src/androidTest/java/software/iva/ivaapp/MainActivity.java
Then I read in an issue that Kotlin doesn't work with Patrol. So I rewrote the MainActivity in Java and moved it to:

css
Code kopieren
android/app/src/main/java/software/iva/ivaapp/MainActivity.java
With that change, I ended up with two Java activities (MainActivity and MainActivityTest), but that didn't work either.

2.) I almost always wiped the emulators.

3.) I tried several emulators, but all of them were using API 35. Maybe trying different APIs will help. After testing it out, I'll come back and let you know the result.

Thank you!

@github-actions github-actions bot removed the waiting for response Waiting for user's response label Jan 15, 2025
@zoskar zoskar added the waiting for response Waiting for user's response label Jan 15, 2025
@zoskar
Copy link

zoskar commented Jan 15, 2025

@dthuesen Please also double check path and content of MainActivityTest and compare it to (Android) Setup guide. It would be great if you could provide its path here.

Patrol does not generate MainActivityTest.java file on its own, you need to set it up during setup - as mentioned in setup guide above

@dthuesen
Copy link
Author

@zoskar Thank you for the hint with API 35. That was the main problem. After I set up an emulator with API 34 the test got attached to the app.

Solution summary:

  1. use emulator with API 34

  2. working directory structure for android:

    MainActivity (see also 3.):
    android/app/src/main/java/software/iva/ivaapp/MainActivity.java, where software/iva/ivaapp is the package_name

    MainActivityTest:
    android/app/src/androidTest/java/software/iva/ivaapp/MainActivityTest.java, where software/iva/ivaapp is the package_name

  3. Since I read, that Kotlin for the MainActivit might not work well with the MainActivityTest in Java, I implemented the former as Kotlin code written MainActivity now as Java code

  4. As my app exists already for several years, I also had to implement some changes to main.dart for not only initApp but also to make Riverpod and Easylocation work. Both both sit pretty high up in the widget tree (wrapped around App() call as passed in Widget argument to runApp(), and so I had to figure out how to get them also be callable from within patrolTest. But that was easy to solve:

Future<String?> initApp() async {
    /// application initialization
}
Widget buildRootApp(String? deviceLocale) {    
    /// constructing the root widget with ProviderScope, EasyLocalization, and BetterFeedback
}
void main() async {
  final logger = Logger();
  await runZonedGuarded(() async {
    WidgetsFlutterBinding.ensureInitialized();
    final deviceLocale = await initApp();
    runApp(
        buildRootApp(deviceLocale),
    );
  }, (e, s) {
    logger.error('Flutter ASYNCHRONOUS ERROR', error: e, stackTrace: s);
  });
}

class App extends ConsumerStatefulWidget {
  const App({super.key});

  @override
  ConsumerState<App> createState() => _AppState();
}

class _AppState extends ConsumerState<App> {
    /// the app root and so on
}

Hope this helps others, too.

Thank you @zoskar, again, for your really fast reply.

@github-actions github-actions bot removed the waiting for response Waiting for user's response label Jan 16, 2025
@dthuesen
Copy link
Author

...and to be clear: for me, the problem is solved and Patrol is a great tool.

@zoskar zoskar closed this as completed Jan 16, 2025
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants