Sha256: 9de5a944d74218d8da0f750d96a4edae7ad0afd5071b2fde581e859ccec0332a

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

require "childprocess"

module Acouchi
  class TestRunner
    def initialize configuration
      @configuration = configuration
    end

    def adb
      @adb ||= Which.find_executable("adb")
    end

    def start
      force_stop
      ProcessLauncher.new(adb, "forward", "tcp:7103", "tcp:7103").start_and_crash_if_process_fails
      @test_runner_process = ProcessLauncher.new(adb, "shell", "am", "instrument", "-w", "#{@configuration.target_package}/android.test.InstrumentationTestRunner")
      @test_runner_process.start_in_background

      while ready? == false
        sleep 0.1
      end
    end

    def stop
      HTTParty.get("http://127.0.0.1:7103/finish") rescue nil
      @test_runner_process.stop
    end

    private
      def ready?
        HTTParty.get("http://127.0.0.1:7103/").body == "Acouchi" rescue false
      end

      def force_stop
        ChildProcess.build(adb, "shell", "am", "force-stop", @configuration.target_package).start.wait
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acouchi-0.0.4 lib/acouchi/test_runner.rb
acouchi-0.0.3 lib/acouchi/test_runner.rb