Skip to content

Add a @visibleForTesting way to override commonly modified template values in apps created by tests (such as AGP version) #153399

Open

Description

@gmackall

We have a lot of integration tests with hardcoded versions of files that get output from flutter create or flutter create <template>.

Ex (but there are more):
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/integration.shard/test_data/deferred_components_project.dart
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/integration.shard/test_data/plugin_project.dart
https://github.com/flutter/flutter/blob/master/dev/devicelab/lib/framework/dependency_smoke_test_task_definition.dart

These test won't accurately test the state of our current templates if the templates change. Perhaps we could refactor the flutter tool to expose something like _overwriteFromTemplate at a @visibleForTesting level for the purposes of integration tests? So that we aren't relying on the specific text content of the gradle build files, but rather just on the versions that we are intending to overwrite.

This functionality is not a feature to lower the maintenance effort it is a feature that will increase the fidelity of our testing that ensures a broad range of AGP/Gradle/Kotlin values continue to work and not regress.

Activity

  1. added
    team-androidOwned by Android platform team
    c: proposalA detailed proposal for a change to Flutter
    on Aug 13, 2024
  2. gmackall commented on Aug 14, 2024

    @gmackall
    MemberAuthor

    cc @christopherfujino, does this seem like a reasonable suggestion to you/do you know if any other platforms modify versions/values that are in template outputs in integration tests?

  3. christopherfujino commented on Aug 14, 2024

    @christopherfujino
    Contributor

    Perhaps we could refactor the flutter tool to expose something like _overwriteFromTemplate at a @VisibleForTesting level for the purposes of integration tests?

    Can you clarify more what this would do?

    I would add that I think there's value in both testing a brand new app built from the current templates (I think this is what the build tests do?) as well as testing a hard-coded app configuration, so that we know when we're breaking existing apps. Whether what we're currently doing is the optimal strategy is absolutely something we should examine more carefully.

    cc @andrewkolos

  4. gmackall commented on Aug 14, 2024

    @gmackall
    MemberAuthor

    Can you clarify more what this would do?

    Sure, the thought is that for tests like the ones that use this method:

    Future<ProcessResult> buildFlutterApkWithSpecifiedDependencyVersions({
    ,
    instead of defining the gradle file content as a string that we then use to override existing files:

    <create>
    ...
    // Modify gradle version to passed in version.
      final File gradleWrapperProperties = File(fileSystem.path.join(
          app.path, 'android', 'gradle', 'wrapper', 'gradle-wrapper.properties'));
      final String propertyContent = gradleWrapperPropertiesFileContent.replaceFirst(
        gradleReplacementString,
        versions.gradleVersion,
      );
    ...
    <build>
    

    We would do something along the lines of

    <create>
    ...
    Project testProject = Project.fromDirectory(app.path)
    testProject.overwriteFromTemplate(gradleVersion: gradleVersion, agpVersion: agpVersion,...)
    ...
    <build>
    

    I would add that I think there's value in both testing a brand new app built from the current templates (I think this is what the build tests do?) as well as testing a hard-coded app configuration, so that we know when we're breaking existing apps.

    I agree, I think we should still have both. I guess what I am asking for is slightly different than either of those two: the ability to easily write tests that confirm that someone can, for a given template format, change Gradle/AGP/compileSdk/etc... versions around and still build successfully (which is essentially what the tests in

    return buildFlutterApkWithSpecifiedDependencyVersions(versionTuples: versionTuples, tempDir: tempDir, localFileSystem: fileSystem);
    are intended to do).

  5. added
    triaged-androidTriaged by Android platform team
    c: new featureNothing broken; request for a new capability
    fyi-infraFor the attention of Infrastructure team
    P2Important issues not at the top of the work list
    on Aug 15, 2024
  6. changed the title [-]Consider refactoring integration tests with hardcoded template files[/-] [+]Add a `@visibleForTesting` way to override commonly modified template values in apps created by tests (such as AGP version)[/+] on Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions