3

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
    ...
halfer
  • 18,701
  • 13
  • 79
  • 158
Inês
  • 796
  • 3
  • 11
  • 23

1 Answers1

2

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

Community
  • 1
  • 1
psykid
  • 378
  • 3
  • 15
  • 1
    Thank you so much :) Would you happen to know the answer for the second part of the question (how to programatically run it? If you do I can mark your answer as correct :) – Inês Sep 17 '15 at 13:42
  • Thank you for editing your answer. But I still have one more question :) I want to make it available for download without providing the source code but when I run anything with gradle it tries to build it again but nothing good comes out of it because there are is no source code (it replaces the apk previously created). – Inês Nov 24 '15 at 11:21
  • I figured it out. If you edit the last part I can mark yours as correct (afterall you gave me more than half of what I needed). Instead of using gradle to run the tests you could just: adb install .apk adb shell am instrument -w packageWithTest/android.support.test.runner.AndroidJUnitRunner for more executions see here http://developer.android.com/intl/es/reference/android/support/test/runner/AndroidJUnitRunner.html – Inês Nov 24 '15 at 17:01
  • you are right! and again for using these commands from java you can use process builder. I didnt tried it though – psykid Nov 25 '15 at 12:01