android / android/android-test

IntentsTestRule does not capture immediate intents

Open
#276 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

### Description

When using IntentTestRule, Intents that get started immediately (for example from `onCreate` method of the tested activity) do not get matched.

### Steps to Reproduce

1. Create an activity that starts another activity in its `onCreate` method
2. Create test for that activity using `IntentsTestRule` that attempts to match start intent
3. Test will fail -

### Expected Results

Start of another activity should be recorded

### Actual Results

Intents will not detect any intents (error message will print out `Recorded intents:[]`)

### AndroidX Test and Android OS Versions

`espresso-intents` 3.1.1
`Android` 9

### Workaround

Workaround to the issue is simple: Create a copy of `IntentsTestRule` and initialize intents in `beforeActivityLaunched` instead of in `afterActivityLaunched`

Contributor guide

Open the contributing guide

Research direction

Start by reading IntentsTestRule and comparing when intents are initialized in beforeActivityLaunched versus afterActivityLaunched. Reproduce an activity that starts another activity from onCreate using espresso-intents 3.1.1, then verify that the start is recorded instead of producing Recorded intents:[].

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.