title: How Do We Inherit Test Classes Across Android Library Modules?
body: <p>I have an Android Studio project with two library modules: <code>foo-module</code> and <code>bar-module</code>. Each implements a library, with <code>foo-module</code> defining a strategy interface and <code>bar-module</code> depending upon <code>foo-module</code> and implementing such a strategy. <code>foo-module</code> has instrumentation tests (<code>foo-module/src/androidTest/</code>) to test its core code, using a stub strategy implementation, and <code>bar-module</code> should have its own instrumentation tests.</p>
  
  <p>I defined an <code>AbstractTests</code> class in <code>foo-module/src/androidTest/</code> that does most of the actual testing. I also have a <code>StubTests</code> class in <code>foo-module/src/androidTest/</code> that extends <code>AbstractTests</code> and implements the necessary <code>abstract</code> methods to complete the test case (providing an implementation of the strategy, etc.). This all works great.</p>
  
  <p>In <code>bar-module/src/androidTest/</code>, I created a <code>BarStrategyTests</code> class, designed to mirror <code>StubTests</code>, but provide the strategy implemented in <code>bar-module</code>. However, <code>BarStrategyTests</code> cannot see <code>AbstractTests</code>, even though I have <code>compile project(':foo-module')</code> in my <code>build.gradle</code> file, and the main (non-test) classes in <code>bar-module</code> can work fine with the main (non-test) classes in <code>foo-module</code>. IOW, while the <code>project()</code> dependency handles regular code, it does not handle <code>androidTest/</code> code. I get "error: package com.commonsware.foo.test does not exist".</p>
  
  <p>I tried also adding <code>androidTestCompile project(':foo-module')</code>, with the same result.</p>
  
  <p>What is the recipe for sharing instrumentation test code between modules?</p>
  
  <p>Temporarily, I can clone <code>AbstractTests</code>, but that's not a great long-term solution.</p>
  
  <p><a href="https://stackoverflow.com/q/31814812/115145">This SO question</a> covers similar ground for ordinary Java. Has anyone tried the options in <a href="https://stackoverflow.com/a/32780697/115145">the one answer</a> and gotten them to work for Android instrumentation tests? The first option (move the common testing code into yet another module as regular non-test code) seems plausible, but I have no idea if the other two will work well with the <code>com.android.library</code> plugin instead of the <code>java</code> plugin.</p>