0

I am executing test cases via the adb shell. For the first time it runs, but when I change the codes and rerun the commands of the shell, it gives results for previous tests that were created. How can I make the test run the current code via the adb shell after changes have been made.

adb shell am force-stop com.example.plainolnotes

adb push "C:\Users\Enoch\Downloads\Lynda\Ex_Files_NoteTaking_Android\Ex_Files_NoteTaking_Android\Exercise Files\06_Finalize\PlainOlNotes\app\build\outputs\apk\app-debug-androidTest.apk" /data/local/tmp/com.example.plainolnotes.test

adb shell pm install -r "/data/local/tmp/com.example.plainolnotes.test"

adb shell am instrument -w -r   -e debug false -e class com.example.plainolnotes.MainActivityAutomatedTest com.example.plainolnotes.test/android.support.test.runner.AndroidJUnitRunner

These are the codes I execute in my adb shell and it is the same as android executes it in my console. Answers will be really appreciated.

user3701188
  • 638
  • 3
  • 7
  • 23

1 Answers1

2

You need to recompile your test apk. I'm guessing you are modifying your test on your IDE.

Because you are pushing your APK using the command line, you need to make sure the changes on the code actually triggers a new apk build including your new code before actually running the commands again.

Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
  • Estvill is there an adb command to trigger changes of the code or a new apk build – user3701188 May 23 '17 at 07:27
  • As far as I know you can not listen for code changes to re-build. However I don't know exactly why you are running such a complicated set of commands. `./gradlew connectedAndroidTest' should take care of everything (build updated apk, build updated test-apk, install both on device, execute tests, generate reports, uninstall ). – Robert Estivill May 23 '17 at 10:46
  • how do I run a single test class using gradle. (gradlew cAT --tests *.MainActivityAutomatedTest) gives me an error : ( What went wrong: Problem configuring task :app:connectedAndroidTest from command line. > Unknown command-line option '--tests'. ) But gradlew cAT runs fine. I want to run a single class – user3701188 May 23 '17 at 21:41
  • https://stackoverflow.com/questions/24951421/how-can-i-run-a-single-test-with-gradle-android – Robert Estivill May 23 '17 at 21:46
  • INSTRUMENTATION_STATUS: Error=Unable to find instrumentation target package: com.example.plainolnotes. This is error I am receiving I dont think its copying the files to the test data app package – user3701188 May 23 '17 at 22:03
  • Your parameters are wrong most likely. You test package is `com.example.plainolnotes.test` and NOT `com.example.plainolnotes` – Robert Estivill May 23 '17 at 22:22
  • Still getting the same error, but as stated from the test docs, you can do something like this ./gradlew testVariantName --tests *.sampleTestMethod But that is not working and I am perceiving that you can do it for a class name as well – user3701188 May 24 '17 at 09:41