android espresso:从命令行运行测试

时间:2016-07-09 05:24:16

标签: android android-espresso

我有一个包含所有测试类的test.espresso包。 我试图从命令行运行单个测试类,但它最终运行所有测试类。

adb shell am instrument -w \ com.demo.app.test / android.support.test.runner.AndroidJUnitRunner

如何运行单个测试类。我想使用bamboo(就像jenkins)在单独的工作中单独运行所有测试类。

3 个答案:

答案 0 :(得分:3)

这对我有用(改变是粗体:

collect($orders)->pluck('orderId')->all(); -e class full.path.and.TestClassName adb shell am instrument -w

基于:https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax(查看“class”的选项)。

答案 1 :(得分:0)

通过命令行

运行

启动设备。我使用Genymotion所以我会这样做

gmtool admin start DeviceName

通过命令行安装

对于ADB

对于ADB,

应该是启动时控制台从A​​ndroid工作室输出的内容。

$ adb push /Users/x/x-android/app/build/outputs/apk/x-debug.apk 
$ adb shell pm install -r "/data/local/tmp/com.x"

$ adb push /x/x/x-android/app/build/outputs/apk/x-debug-androidTest.apk /data/local/tmp/com.x.test
$ adb shell pm install -r "/data/local/tmp/com.x.test"

对于Genymotion来说,

gmtool device install ~/Desktop/x.apk 
gmtool device install ~/Desktop/x-androidTest.apk 

对于Genymotion,将Genymotion连接到ADB

gmtool device adbconnect

开始测试。这适用于ADB和Geny

adb shell am instrument -w -r   -e debug false -e class com.x.MyTest com.x.test/android.support.test.runner.AndroidJUnitRunner

答案 2 :(得分:0)

如果您正在使用gradle,则可以直接使用gradle任务来实现它。会是这样的:

./gradlew connectedAndroidTest-为连接的设备上的所有版本安装并运行仪器测试。

要运行特定的风味:

./gradlew connectedMyAppFlavorDebugAndroidTest

从构建应用程序,在连接的设备上安装,运行测试并最终卸载应用程序,它可以为您完成所有操作。

如果您不确定执行测试所需的确切gradle任务,请运行以下命令以获取所有可用的gradle任务:

./gradlew tasks

您将获得带有简短说明的所有任务的列表。