Reputation: 1
Now I wrote a batch script to run the command like:
adb -s emulator-5556 shell am instrument -e class com.example.test.locationListTest -w com.example.test/android.test.InstrumentationTestRun
Then at the console I get results like FAILURE!!! Tests run: 5 fail:4
or OK
.
I use if errorlevel 0
to determine the upper command, but it gives me 0 no matter the upper command gives me, OK or FAILURE.
I need to do this in batch script like this:
if(adb -s emulator-5556 shell ..... test.InstrumentationTestRun == SUCCESS )
do (.........)
else (.........)
Upvotes: 0
Views: 1373
Reputation: 319
Rather than doing it via adb you can instead run your instumentation tests with gradle.
Here is an example bash script to do this:
#!/bin/bash
CMD="./gradlew connectedAndroidTest"
$CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed $CMD"
exit 1
fi
exit 0
Upvotes: -1
Reputation: 160
What about something simple, like:
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
Upvotes: 1
Reputation: 41287
if errorlevel 0
is always true.
You need to use if not errorlevel 1
when you use that style of line for testing.
Upvotes: 1
Reputation: 7105
Try this:
@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
)
)
This way, errorlevel will work because it's coming from Find.
Upvotes: 1