Beispiel #1
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void run(java.util.Collection<ITestRunListener> listeners) throws com.android.ddmlib.TimeoutException, com.android.ddmlib.AdbCommandRejectedException, com.android.ddmlib.ShellCommandUnresponsiveException, java.io.IOException
        public void run(ICollection <ITestRunListener> listeners)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String runCaseCommandStr = String.format("am instrument -w -r %1$s %2$s", getArgsCommand(), getRunnerPath());
            string runCaseCommandStr = string.Format("am instrument -w -r {0} {1}", argsCommand, runnerPath);

            Log.i(LOG_TAG, string.Format("Running {0} on {1}", runCaseCommandStr, mRemoteDevice.serialNumber));
            string runName = mRunName == null ? mPackageName : mRunName;

            mParser = new InstrumentationResultParser(runName, listeners);

            try
            {
                mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser, mMaxTimeToOutputResponse);
            }
            catch (IOException e)
            {
                Log.w(LOG_TAG, string.Format("IOException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                // rely on parser to communicate results to listeners
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
            catch (ShellCommandUnresponsiveException e)
            {
                Log.w(LOG_TAG, string.Format("ShellCommandUnresponsiveException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(string.Format("Failed to receive adb shell test output within {0:D} ms. " + "Test may have timed out, or adb connection to device became unresponsive", mMaxTimeToOutputResponse));
                throw e;
            }
            catch (TimeoutException e)
            {
                Log.w(LOG_TAG, string.Format("TimeoutException when running tests {0} on {1}", packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
            catch (AdbCommandRejectedException e)
            {
                Log.w(LOG_TAG, string.Format("AdbCommandRejectedException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
        }
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void run(java.util.Collection<ITestRunListener> listeners) throws com.android.ddmlib.TimeoutException, com.android.ddmlib.AdbCommandRejectedException, com.android.ddmlib.ShellCommandUnresponsiveException, java.io.IOException
        public void run(ICollection<ITestRunListener> listeners)
        {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final String runCaseCommandStr = String.format("am instrument -w -r %1$s %2$s", getArgsCommand(), getRunnerPath());
            string runCaseCommandStr = string.Format("am instrument -w -r {0} {1}", argsCommand, runnerPath);
            Log.i(LOG_TAG, string.Format("Running {0} on {1}", runCaseCommandStr, mRemoteDevice.serialNumber));
            string runName = mRunName == null ? mPackageName : mRunName;
            mParser = new InstrumentationResultParser(runName, listeners);

            try
            {
                mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser, mMaxTimeToOutputResponse);
            }
            catch (IOException e)
            {
                Log.w(LOG_TAG, string.Format("IOException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                // rely on parser to communicate results to listeners
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
            catch (ShellCommandUnresponsiveException e)
            {
                Log.w(LOG_TAG, string.Format("ShellCommandUnresponsiveException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(string.Format("Failed to receive adb shell test output within {0:D} ms. " + "Test may have timed out, or adb connection to device became unresponsive", mMaxTimeToOutputResponse));
                throw e;
            }
            catch (TimeoutException e)
            {
                Log.w(LOG_TAG, string.Format("TimeoutException when running tests {0} on {1}", packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
            catch (AdbCommandRejectedException e)
            {
                Log.w(LOG_TAG, string.Format("AdbCommandRejectedException {0} when running tests {1} on {2}", e.ToString(), packageName, mRemoteDevice.serialNumber));
                mParser.handleTestRunFailed(e.ToString());
                throw e;
            }
        }