Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Feature Request: allow custom `Factory` to be passed into `ActivityScenario` (similar to `FragmentScenario`)

Open
#1,738 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, java, kotlin
Domain
mobile, testing

Research direction

Start with ActivityScenario.java and compare its launch APIs with FragmentScenario.kt's launchInContainer factory support. Trace how ActivityScenario currently creates activities, then identify the API and test changes needed to support custom factories and activity options. Done means custom-constructor activities can be launched with injected dependencies in tests.

Written by the indexing model from the issue text.

Description

Description

API 28 introduced AppComponentFactory. It allows one to provide a custom constructor to any Android component, including an Activity. Most apps cannot utilize this feature due to the minimum API requirement. For those that can, defining a custom constructor for an Activity means that there may be no empty default constructor available.

That complicates the usage of ActivityScenario: it doesn't support a Factory parameter to provide custom dependencies (see here).

To address this issue, I propose that ActivityScenario should support a Factory parameter, similar to FragmentScenario (see here). This would enable developers to take full advantage of providing custom dependencies during tests:

val scenario = launchActivity(
  activityOptions, // we likely want to support activity options.
  factory = { MyCustomActivity(Deps1(), Deps2()) } // where factory is a `() -> Activity` or similar.
)
Steps to Reproduce
  1. Create an app using API 28 or above.
  2. Create a custom AppComponentFactory.
  3. Create an Activity using a custom constructor.
  4. Try to write a test using the custom constructor providing custom dependencies in the test, similar to Fragments: Provide Dependencies.
Expected Results

Similar to FragmentScenario, ActivityScenario should support custom dependencies.

Actual Results

There is no way to provide custom dependencies without modifying the whole AppComponentFactory of the tests or using workaround (i.e., leaving the Activity as an open class and provide a custom implementation in the test).

AndroidX Test and Android OS Versions

Current version: 1.5.0

Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
2d 22h
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/android-test

All issues in android/android-test

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.