Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share test classes between modules

I would like to be able to have common test code in a library module of my android projects, so that the different apps in the project can use them.

The problem is, apps cannot import classes from <library>/src/androidTest/java, and if I move that at code into src\main, it would have to move dependencies from androidTestCompile to compile (more dependencies to the release build).

The only solution right now is to create a separate library to hold the shared test classes, however this has the downside of adding a new library to the project structure, which is not that big a deal, but I'd like to know nonetheless if there are better solutions.

I'd rather implement a Gradle hack at this point if any Gradle (Android plugin) wizards out there can help me find one.

like image 961
Anthony Avatar asked Nov 08 '22 06:11

Anthony


1 Answers

Since I got no answers, I might as well answer my own question.

I ended up using the solution I already mentioned in my question:

Create a library with shared test classes (not actual test cases, but common code to be used in the final ones) under src/main and import it with androidTestCompile or androidTestImplementation for recent gradle versions.

Got a solution that doesn't involve adding a module? I won't accept my own answer since it doesn't exactly answer the question.

like image 156
Anthony Avatar answered Nov 15 '22 11:11

Anthony