Reputation: 648
I want to achieve something like this:
[ComponentTestsModule] com.android.test
[FunctionalTestsModule] com.android.test
both depends on
-> [TestLibraryModule] ?
which depends on
-> [AppModule] com.android.application
Is there any way to do it with android Gradle plugin 3.0+?
I want different test runners for different types of tests, also target different variants.
It is working right now with single codebase under androidTest
, but with ugly switches in the custom test runner.
I want to share the same page-objects between different types of tests, and maybe some utility code. Problem is: that page objects must have access to R class of app (locators: R.id.*)
None of the module types I'm aware of can depend on APK-producing module, expect from com.android.test
, but i cannot depend from com.android.test
with another com.android.test
.
Upvotes: 27
Views: 3419
Reputation: 3741
I have recently faced this problem and just want to share my solution in case some body needs it.
What I have done so far (not a perfect solution - I guess, but at least it works).
Create a new module
named testing_base or some thing like that
In testing_base module
only put things related to testing (Like the code you want it to be shared between modules) in to normal packages, NOT in the test packages/folders.
From others module, try to import things from testing_base module
ex:
testImplementation project(":testing_base")
Hope it can helps someone, happy testing!
Upvotes: 8
Reputation: 83517
I want different test runners for different types of tests
To run a test class with a specific test runner, use the @RunWith
annotation.
also target different variants
To target a specific variant, create your tests in app/src/androidTestVariantName
for instrumented tests or in app/src/testVariantName
for unit tests.
Upvotes: -4