Make Android test project available without source code ("make apk of the test-project")

2k Views Asked by At

I have an Android test project based on InstrumentationTestCase and using AndroidJUnitRunner.

I need to provide my project to another party but I don't want to provide the source code.

Currently I have two projects:

  • a Java project that installs the APK of the application I want to test in the device: I have the jar file for this project
  • an Android Test Project that tests the application.

The Java project is currently starting the AndroidTestProject by programmatically running "gradlew connectedCheck".

Now I want to give both the installer and the test project to other people but I don't want to disclose the source code. So it would be the equivalent of creating the apk but for a test project.

So my two questions are:

  • how to obtain the "executable" for my test project
  • how to programatically run it (I assume that without the source code gradlew cC doesn't work).

I don't know if this matters so here goes: my project hierarchy is

Project
    .gradle
    .idea
    app
        build
        src
            androidTest
                java
                    package
                        sub-packages and java files
            main
                AndroidManifest
            app.iml
            build-gradle
            proguard-rules.pro
    build
    gradle
    ...
1

There are 1 best solutions below

4
On BEST ANSWER

I am gonna change my complete answer! Never thought this would be this easy.

On the right side of the android studio there will be gradle window. Open it and refresh it once to see your current project in it.

In the tasks section, build subsection -> assemble and assemble test options will be there. Assemble for your normal apk and assemble test for your test apk. These will be generated in the app/build/output/apk folder.

As for running them programatically, use gradle tasks (command line function in there for ./gradlew test --continue ) which will run tests after the build or if u want to use java use it as here. Using C is always easy for shell commands ;)

Edit 2: as Ines have mentioned in the comments, to run the tests you could just use:

adb install name-of-the-apk.apk 
adb shell am instrument -w packageWithTest/android.support.test.runner.AndroidJUnitRunner

for more executions see here