【问题标题】:How can I get the exit code or exit status after finish a robotium test on the command line在命令行上完成机器人测试后如何获取退出代码或退出状态
【发布时间】:2014-02-28 23:55:42
【问题描述】:

现在我写了一个批处理脚本来运行如下命令:

adb -s emulator-5556 shell am instrument -e class com.example.test.locationListTest -w com.example.test/android.test.InstrumentationTestRun

然后在控制台我得到类似FAILURE!!! Tests run: 5 fail:4OK 的结果。

我使用if errorlevel 0 来确定上层命令,但是无论上层命令给我OK 还是FAILURE,它都会给我0。

我需要像这样在批处理脚本中执行此操作:

if(adb -s emulator-5556 shell ..... test.InstrumentationTestRun == SUCCESS )
do (.........)
else (.........)

【问题讨论】:

    标签: batch-file command-line cmd robotium exit-code


    【解决方案1】:

    试试这个:

    @echo off
    setlocal
    
    set "adb=adb -s emulator-5556 shell am instrument -e class com.example.test.locationListTest -w com.example.test/android.test.InstrumentationTestRun"
    for /f "tokens=*" %%a in ('%adb%^|find /i "Ok"') do (
      if not errorlevel 1 ( 
             Echo Success 
      ) else (
             echo Failure
      )
    )
    

    这样,errorlevel 将起作用,因为它来自 Find。

    【讨论】:

      【解决方案2】:

      if errorlevel 0 始终为真。

      当你使用这种风格的线进行测试时,你需要使用if not errorlevel 1

      【讨论】:

        【解决方案3】:

        那么简单的事情呢,比如:

        adb -s emulator-5556 shell am instrument -e class com.example.test.locationListTest -w com.example.test/android.test.InstrumentationTestRun | grep "Failures"
        if [ $? -eq 0 ]; then
            echo "## TEST FAILED ##"
            exit 1
        fi
        

        【讨论】:

          【解决方案4】:

          您可以使用 gradle 运行仪器测试,而不是通过 adb 进行。

          这是一个执行此操作的示例 bash 脚本:

          #!/bin/bash
          CMD="./gradlew connectedAndroidTest"
          $CMD
          RESULT=$?
          if [ $RESULT -ne 0 ]; then
           echo "failed $CMD"
           exit 1
          fi
          exit 0
          

          【讨论】:

            猜你喜欢
            • 2018-11-04
            • 1970-01-01
            • 2018-09-18
            • 1970-01-01
            • 2011-06-28
            • 2023-02-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多