I have a project structue like:
--app
--module2 //library module
--module3 //library module
I am writing instrumentation test cases for my multi module android project with jacoco code coverage. If I execute the instrumentation test cases from 'app' module, code coverage is only generated for 'app' module classes.
So, in order to get code coverage for 'module2' & 'module3' classes; I have written instrumentation test cases in respective modules.
Issue arises when I execute instrumentation test cases in non-app modules, am unable to launch the main activity, app is not launching during instrumentation and test cases are failing.
Root cause is:
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Rule is not declared in 'module2' & 'module3' which launch 'MainActivity.class'. I cannot import 'MainActiviy' to these modules because of some circular dependency issues.
Error:
java.lang.RuntimeException: No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar?
How to tackle this ?
NB: This question is exclusively for instrumentation test, not for unit test(this is already handled in unit tests)