0

I am working on creating a library project which accepts application context during initialization of library. During one method call of the library, I am opening an activity of the library, which is working as expected.

I am trying to write a test case to validate that, when that particular library method is invoked, startActivity() is called. I found many test case examples which starts one activity from another activity, but not of starting activity using context.

Thanks in Advance!

Ravi Bhatt
  • 1,930
  • 1
  • 14
  • 27
  • This may help https://stackoverflow.com/questions/29969545/whats-the-difference-between-gettargetcontext-and-getcontext-on-instrumentat – Toris Jan 28 '19 at 14:43
  • Thanks @Toris, the link you provided talks more about instrumentation tests which runs on device. I am trying to write unit tests, so seems not much helpful. – Ravi Bhatt Jan 28 '19 at 14:48
  • Wel.. this may be more clear. https://stackoverflow.com/questions/8605611/get-context-of-test-project-in-android-junit-test-case?noredirect=1&lq=1 – Toris Jan 28 '19 at 14:54
  • Thanks @Toris. This link shows how to extract out context, but my question is out of that context, how to validate that any activity is started using that context. For example my code is ``context.startActivity()``. I am not getting any example that how to validate starting activity from context through robolectric. – Ravi Bhatt Jan 29 '19 at 06:08
  • I think it's a test with a `context` which can be get through `InstrumentationRegistry.getTargetContext()` etc, but if it doesn't match your case, please look at Kuba Spatny's answer in this link. https://stackoverflow.com/questions/3170706/how-do-you-get-hold-of-an-android-context-for-a-junit-test-from-a-java-project – Toris Jan 30 '19 at 00:10

0 Answers0