I understand that you want to test on devices/emulators. We also have 
support for running tests on the local JVM, but that's mostly for 
android-independent "business logic" (see here 
<http://g.co/androidstudio/unit-testing>).

What usually happens is that two APKs are created - one with "main" code, 
one with test code. They are put on the same classpath and tests are run. 
To test library code, you have two options:

1. Put your tests in the library module. If your library contains custom 
widgets etc., and you want to e.g. write UI tests with Espresso, you may 
need to create test-only activities that will host them. You put all of 
that (and a test-only Manifest that declares the activities) under 
mylib/src/androidTest. Android Studio may still get a bit confused with 
test-only manifests, there will be some unnecessary red lines in the editor.

2. Just put your testing logic in the main application. This way you test 
the "finished" product, using the main application as a "host" for library 
code. You can then use flavors or test runner arguments to choose to run 
only a subset of all your tests (e.g. only tests that cover parts from 
library1).

HTH,

Michal

On Friday, August 14, 2015 at 7:25:58 PM UTC+1, [email protected] 
wrote:
>
> We have a main android application project that depends on many libraries. 
>  We want to have unit tests for each library by having a separate 'tests' 
> folder in each library project.  The problem with this is that our library 
> tests require the main application to be installed and running before 
> running the tests.  
>
> Is there any way to tell the testing framework to create a testing APK 
> with the main application's code and the library's test code?  
>
> For example lets say I have a project named MainApplication and libraries 
> named Library1 and Library2.  MainApplication also depends on Library1 and 
> Library2.  From what I understand the usual way to test Library1 is that 
> the testing framework creates an APK that includes the Library1's code and 
> also Library1's tests.  What I would like to do is if I was running 
> Library1's tests then the generated APK would contain MainApplication's 
> code and Library1's tests.  This is so MainApplication gets installed and 
> is running before Library1 runs its own tests. Likewise if I 
> was running Library2's tests then the generated APK would 
> contain MainApplication's code and Library2's tests.
>
> Is this approach even possible or would I have to include all of the tests 
> that I was going to put in each individual library inside the 
> MainApplication's 'tests' folder?
>
> Any help would be appreciated, thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to