src/main/java/com/simpligility/maven/plugins/android/standalonemojos/MonkeyRunnerMojo.java
protected void run( IDevice device, ITestRunListener... iTestRunListeners ) throws MojoExecutionException,
            MojoFailureException
    {

        this.mTestListeners = iTestRunListeners;

        getLog().debug( "Parsed values for Android Monkey Runner invocation: " );

        CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
        if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
        {
            executor.setCustomShell( new CustomBourneShell() );
        }
        executor.setLogger( this.getLog() );

        String command = getAndroidSdk().getMonkeyRunnerPath();

        List< String > pluginParameters = new ArrayList< String >();

        if ( parsedPlugins != null && parsedPlugins.length != 0 )
        {
            for ( String plugin : parsedPlugins )
            {
                String pluginFilePath = new File( project.getBasedir(), plugin ).getAbsolutePath();
                pluginParameters.add( "-plugin " + pluginFilePath );
            }
        }

        if ( parsedPrograms != null && !parsedPrograms.isEmpty() )
        {
            handleTestRunStarted();
            errorListener = new MonkeyRunnerErrorListener();
            executor.setErrorListener( errorListener );

            for ( Program program : parsedPrograms )
            {
                List< String > parameters = new ArrayList< String >( pluginParameters );

                String programFileName = new File( project.getBasedir(), program.getFilename() ).getAbsolutePath();
                parameters.add( programFileName );
                String testName = programFileName;
                if ( testName.contains( "/" ) )
                {
                    testName.substring( testName.indexOf( '/' ) + 1 );
                }
                mCurrentTestIndentifier = new TestIdentifier( "MonkeyTest ", testName );

                String programOptions = program.getOptions();
                if ( parsedInjectDeviceSerialNumberIntoScript != null && parsedInjectDeviceSerialNumberIntoScript )
                {
                    parameters.add( device.getSerialNumber() );
                }
                if ( programOptions != null && !StringUtils.isEmpty( programOptions ) )
                {
                    parameters.add( programOptions );
                }

                try
                {
                    getLog().info( "Running command: " + command );
                    getLog().info( "with parameters: " + parameters );
                    handleTestStarted();
                    executor.setCaptureStdOut( true );
                    executor.executeCommand( command, parameters, true );
                    handleTestEnded();
                }
                catch ( ExecutionException e )
                {
                    getLog().info( "Monkey runner produced errors" );
                    handleTestRunFailed( e.getMessage() );

                    if ( !isIgnoreTestFailures() )
                    {
                        getLog().info( "Project is configured to fail on error." );
                        getLog().info(
                                "Inspect monkey runner reports or re-run with -X to see monkey runner errors in log" );
                        getLog().info( "Failing build as configured. Ignore following error message." );
                        if ( errorListener.hasError )
                        {
                            getLog().info( "Stack trace is:" );
                            getLog().info( errorListener.getStackTrace() );
                        }
                        throw new MojoExecutionException( "", e );
                    }
                }

                if ( errorListener.hasError() )
                {
                    handleCrash();
                }
            }
            handleTestRunEnded();
        }

        getLog().info( "Monkey runner test runs completed successfully." );
    }
protected void run( IDevice device, ITestRunListener... iTestRunListeners ) throws MojoExecutionException,
            MojoFailureException
    {

        this.mTestListeners = iTestRunListeners;

        getLog().debug( "Parsed values for Android Monkey Runner invocation: " );

        CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
        if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
        {
            executor.setCustomShell( new CustomBourneShell() );
        }
        executor.setLogger( this.getLog() );

        String command = getAndroidSdk().getMonkeyRunnerPath();

        List< String > pluginParameters = new ArrayList< String >();

        if ( parsedPlugins != null && parsedPlugins.length != 0 )
        {
            for ( String plugin : parsedPlugins )
            {
                String pluginFilePath = new File( project.getBasedir(), plugin ).getAbsolutePath();
                pluginParameters.add( "-plugin " + pluginFilePath );
            }
        }

        if ( parsedPrograms != null && !parsedPrograms.isEmpty() )
        {
            handleTestRunStarted();
            errorListener = new MonkeyRunnerErrorListener();
            executor.setErrorListener( errorListener );

            for ( Program program : parsedPrograms )
            {
                List< String > parameters = new ArrayList< String >( pluginParameters );

                String programFileName = new File( project.getBasedir(), program.getFilename() ).getAbsolutePath();
                parameters.add( programFileName );
                String testName = programFileName;
                if ( testName.contains( "/" ) )
                {
                    testName.substring( testName.indexOf( '/' ) + 1 );
                }
                mCurrentTestIndentifier = new TestIdentifier( "MonkeyTest ", testName );

                String programOptions = program.getOptions();
                if ( parsedInjectDeviceSerialNumberIntoScript != null && parsedInjectDeviceSerialNumberIntoScript )
                {
                    parameters.add( device.getSerialNumber() );
                }
                if ( programOptions != null && !StringUtils.isEmpty( programOptions ) )
                {
                    parameters.add( programOptions );
                }

                try
                {
                    getLog().info( "Running command: " + command );
                    getLog().info( "with parameters: " + parameters );
                    handleTestStarted();
                    executor.setCaptureStdOut( true );
                    executor.executeCommand( command, parameters, true );
                    handleTestEnded();
                }
                catch ( ExecutionException e )
                {
                    getLog().info( "Monkey runner produced errors" );
                    handleTestRunFailed( e.getMessage() );

                    if ( !isIgnoreTestFailures() )
                    {
                        getLog().info( "Project is configured to fail on error." );
                        getLog().info(
                                "Inspect monkey runner reports or re-run with -X to see monkey runner errors in log" );
                        getLog().info( "Failing build as configured. Ignore following error message." );
                        if ( errorListener.hasError )
                        {
                            getLog().info( "Stack trace is:" );
                            getLog().info( errorListener.getStackTrace() );
                        }
                        throw new MojoExecutionException( "", e );
                    }
                }

                if ( errorListener.hasError() )
                {
                    handleCrash();
                }
            }
            handleTestRunEnded();
        }

        getLog().info( "Monkey runner test runs completed successfully." );
    }
Actually plays tests.

@param device
the device on which tests are going to be executed.
@param iTestRunListeners
test run listeners.
@throws MojoExecutionException
if exercising app threw an exception and isIgnoreTestFailures is false..
@throws MojoFailureException
if exercising app failed and isIgnoreTestFailures is false.