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 2.0 shortcomings #1341

Closed
bartekpacia opened this issue Jun 10, 2023 · 18 comments
Closed

Patrol 2.0 shortcomings #1341

bartekpacia opened this issue Jun 10, 2023 · 18 comments

Comments

@bartekpacia
Copy link
Contributor

bartekpacia commented Jun 10, 2023

In this issue, we gather a list of problems, bugs, and lacks related to the test bundling feature. This is mostly an extract of problems mentioned in this comment.

Individual issues might be created later.


  • preserve the tree structure of Dart tests when translated to native tests (update: see #1502)

    Given the following hierarchy of the integration_test directory:

    integration_test
    ├── feature_bravo
    │   ├── 1_test.dart
    │   └── 2_test.dart
    └── feature_delta
        ├── 1_test.dart
        └── 2_test.dart
    

    the results are presented like this on a native platform (in the example below: Android:)

    test feature_bravo.1_test.dart ✅
    test feature_bravo.2_test.dart ✅
    test feature_delta.1_test.dart ✅
    test feature_delta.2_test.dart ✅
    

    but should be presented like this instead:

    group feature_bravo
    ├── test 1_test.dart ✅
    └── test 2_test.dart ✅
    group feature_delta
    ├── test 1_test.dart ✅
    └── test 2_test.dart ✅
    

    In other words, the hierarchy is removed, but it's emulated by . (a dot).



  • set-up and tear-down callbacks cannot be used (update: see #1503)

    Or rather: they can be used, but they execute in a very different order.
    This applies to setUp(), setUpAll(), tearDown(), tearDownAll(), and similar.

    Assume there are 3 tests in the integration_test director:

    Source code
    import 'common.dart';
    
    // integration_test/alpha_test.dart
    
    void main() {
      print('PATROL_DEBUG: alpha_test file loaded');
    
      setUp(() {
        print('PATROL_DEBUG: alpha_test setup');
      });
    
      tearDown(() {
        print('PATROL_DEBUG: alpha_test teardown');
      });
    
      patrolTest('alpha_test', nativeAutomation: true, ($) async {
        print('PATROL_DEBUG: alpha_test body');
        await $.pumpWidget(ExampleApp());
      });
    }
    import 'common.dart';
    
    // integration_test/bravo_test.dart
    
    void main() {
      print('PATROL_DEBUG: bravo_test file loaded');
    
      setUp(() {
        print('PATROL_DEBUG: bravo_test setup');
      });
    
      tearDown(() {
        print('PATROL_DEBUG: bravo_test teardown');
      });
    
      patrolTest('bravo_test', nativeAutomation: true, ($) async {
        print('PATROL_DEBUG: bravo_test body');
        await $.pumpWidget(ExampleApp());
      });
    }
    import 'common.dart';
    
    // integration_test/charlie_test.dart
    
    void main() {
      print('PATROL_DEBUG: charlie_test file loaded');
    
      setUp(() {
        print('PATROL_DEBUG: charlie_test setup');
      });
    
      tearDown(() {
        print('PATROL_DEBUG: charlie_test teardown');
      });
    
      patrolTest('charlie test', nativeAutomation: true, ($) async {
        print('PATROL_DEBUG: charlie_test body');
        await $.pumpWidget(ExampleApp());
      });
    }

    Here's how it'll end up being:

    Logs
    $ adb logcat -v color -d | grep -E 'PATROL_DEBUG' | cut -d ':' -f 4,5
     PATROL_DEBUG: alpha_test file loaded
     PATROL_DEBUG: bravo_test file loaded
     PATROL_DEBUG: charlie_test file loaded
     PATROL_DEBUG: alpha_test setup
     PATROL_DEBUG: alpha_test file loaded
     PATROL_DEBUG: bravo_test file loaded
     PATROL_DEBUG: charlie_test file loaded
     PATROL_DEBUG: alpha_test setup
     PATROL_DEBUG: alpha_test body
     PATROL_DEBUG: alpha_test teardown
     PATROL_DEBUG: bravo_test setup
     PATROL_DEBUG: alpha_test file loaded
     PATROL_DEBUG: bravo_test file loaded
     PATROL_DEBUG: charlie_test file loaded
     PATROL_DEBUG: alpha_test setup
     PATROL_DEBUG: alpha_test teardown
     PATROL_DEBUG: bravo_test setup
     PATROL_DEBUG: bravo_test body
     PATROL_DEBUG: bravo_test teardown
     PATROL_DEBUG: charlie_test setup
     PATROL_DEBUG: alpha_test file loaded
     PATROL_DEBUG: bravo_test file loaded
     PATROL_DEBUG: charlie_test file loaded
     PATROL_DEBUG: alpha_test setup
     PATROL_DEBUG: alpha_test teardown
     PATROL_DEBUG: bravo_test setup
     PATROL_DEBUG: bravo_test teardown
     PATROL_DEBUG: charlie_test setup
     PATROL_DEBUG: charlie_test body
     PATROL_DEBUG: charlie_test teardown

    This is because of the way we implemented running a particular test. Tests that appear before it aren't actually skipped – they are run but finish immediately. Think: fallthrough.


  • The main() function must not be asynchronous.

    Example of incorrect test:

    void main() async {
      patrolTest(...);
    }

    Example of correct test:

    void main() {
      patrolTest(...);
    }
@mzdm
Copy link

mzdm commented Jun 13, 2023

Q: Test bundling is optional or it will be the only option in 2.0? setUp, tearDown etc. are quite crucial in our codebase and I am wondering what the workarounds will be

@bartekpacia
Copy link
Contributor Author

A: It'll be the only way of running tests in 2.0.

@bartekpacia
Copy link
Contributor Author

I am wondering what the workarounds will be

You can run set-ups manually at the top of the callback you pass to patrolTest().

Using tear-downs is not recommended since there's no guarantee they'll execute, due to e.g. fatal native crash.

I'm curios to hear what you think about this. I'd also like to bring back support for set-ups and tear-downs but it was decided not needed for 2.0.

@bartekpacia
Copy link
Contributor Author

Please also note that MainActivityTest.java was changed in 2.0.0-dev.3, here's how it must look like now.

@bartekpacia bartekpacia changed the title Test bundling shortcomings Patrol 2.0 shortcomings Jun 23, 2023
@findms
Copy link

findms commented Jun 27, 2023

@bartekpacia In my case I don't have this MainActivityTest.java should I add this file and code according to patrol_cli_2.0.0 documentation as getting some errors in test_bundle.dart and build.gradle on activating patrol_cli to 2.0.0

Is there any way to go back on patrol_cli_1.1.11?

@bartekpacia
Copy link
Contributor Author

Sure, you can easily downgrade to v1:

dart pub global activate patrol_cli ^1.0.0

@EyedBread

This comment was marked as off-topic.

@bartekpacia

This comment was marked as off-topic.

bartekpacia added a commit that referenced this issue Jun 28, 2023
Removed info about `tearDown()` and `setUp()` callbacks when using native automation. These callbacks must not be used in Patrol 2.0. See #1341 for more details.
bartekpacia added a commit that referenced this issue Jun 28, 2023
Removed info about `tearDown()` and `setUp()` callbacks when using native automation. These callbacks must not be used in Patrol 2.0. See #1341 for more details.
@GentiShtjefni

This comment was marked as off-topic.

@bartekpacia

This comment was marked as off-topic.

@pdax-johnlester

This comment was marked as off-topic.

@bartekpacia

This comment was marked as off-topic.

@pdax-johnlester

This comment was marked as off-topic.

@bartekpacia

This comment was marked as off-topic.

@pdax-johnlester

This comment was marked as off-topic.

@bartekpacia

This comment was marked as off-topic.

@jBorkowska
Copy link
Collaborator

There are separate issues for this topics, closing

@jBorkowska jBorkowska removed the epic Idea for a big new feature label Jan 12, 2024
@mateuszwojtczak mateuszwojtczak unpinned this issue Jan 12, 2024
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 19, 2024
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

7 participants