ServiceTestRule not support the Service whicha runs in a separat process
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start at ServiceTestRule.bindService and compare its behavior for the shown MyServiceTest when MyService runs in the default process versus the separate ":ai" process. Reproduce the ClassCastException with the provided example; done means the separate-process service can be bound without the BinderProxy cast failure.
Written by the indexing model from the issue text.
Description
I'm writing the unit tests for MyService, which runs in a separate process android:process=":ai", and the code like this:
//The Service:
class MyService: Service() {
inner class TestBinder() : Binder() {
fun getService() = this@MyService
}
override fun onBind(intent: Intent?): IBinder? {
return TestBinder()
}
}
//The test:
@RunWith(AndroidJUnit4::class)
internal class MyServiceTest {
private val rule = ServiceTestRule()
@Test
fun test() {
val binder = rule.bindService(Intent(ApplicationProvider.getApplicationContext(), MyService::class.java))
val service = (binder as MyService.TestBinder).getService()
}
}
But ClassCastException was thrown:
java.lang.ClassCastException: android.os.BinderProxy cannot be cast to MyService$TestBinder
But test works if I make MyService without separate process.
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from android/android-test
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
android/android-test#681 · 2 comments · 1 reaction ·
-
ξεκσνδξδ Open
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2499 ·
-
ησξξσ Open
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/android-test#2498 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
android/android-test#2473 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
android/android-test#2461 · 6 comments · 4 reactions ·
All issues in android/android-test
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100