Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A way to share code between multiple android test modules

Tags:

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+?

Why I need multiple test modules?

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.

Why I need a test library module?

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.

like image 950
Dmitriy Voronin Avatar asked Aug 31 '17 17:08

Dmitriy Voronin


1 Answers

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).

  1. Create a new module named testing_base or some thing like that

  2. 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.

  3. From others module, try to import things from testing_base module

ex: testImplementation project(":testing_base")

Hope it can helps someone, happy testing!

like image 54
ThaiPD Avatar answered Oct 11 '22 19:10

ThaiPD