Skip to content

Plugin: Become more lenient when test tasks are absent #227

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

Merged
merged 4 commits into from
Oct 24, 2020

Conversation

mannodermaus
Copy link
Owner

@mannodermaus mannodermaus commented Oct 24, 2020

It's possible to disable unit tests for any given variant. This has become even more apparent with the introduction of the new onVariants APIs in Android Gradle Plugin 4. The plugin expects all tasks to be present and aggressively obtains the tasks by name (using getByName(String). This will throw an UnknownTaskException, which is undesirable.

This PR makes the plugin more forgiving when any consumer disables unit test tasks for certain variants. While verifying these cases, the functional tests have been extended to handle foreach loops in the template files as well, which is neat.

Context: #226

The new Variant API, introduced in AGP 4+, allows test tasks to be
disabled on a per-variant basis with an easier API. The plugin must not
expect all test tasks to always be present, since that could result in
UnknownTaskExceptions down the line.

Now, testTaskOf() uses the less direct "findByName()" API rather than "getByName()"
to obtain the AndroidTestTasks, bailing out if a task is absent.
@mannodermaus mannodermaus self-assigned this Oct 24, 2020
@mannodermaus mannodermaus added this to the plugin-1.7.0.0 milestone Oct 24, 2020
@mannodermaus mannodermaus merged commit 580e153 into master Oct 24, 2020
@mannodermaus mannodermaus deleted the feature/allow-absent-test-tasks branch October 24, 2020 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant