[Android][Test]nativedriverインストール

Google Code Archive - Long-term storage for Google Code Project Hosting.
を見ながらインストール。

$ svn checkout https://nativedriver.googlecode.com/svn/trunk nativedriver --username {Google account e-mail address}
$ cd nativedriver/android
$ ant

ビルドが完了すると、nativedriver/android/build配下にこのようなライブラリができる。
server-standalone.jar - テストされる側(アプリケーション内)で使う
client-standalone.jar - テストする側で使う

興味深いのがこのclient-serverモデルはHTTP+JSONプロトコルで通信するらしい。

以下、サンプルのテスト

サンプルプロジェクトをEclipseへインポート

  1. File -> Import
  2. Existing Projects into Workspaceでnativedriver/android/sample-aut/simplelayouts を選択
  3. 同じようにnativedriver/android/test もインポート

android-test projectにはAndroid NativeDriverで書かれたサンプルが含まれている。
simplelayouts projectはテスト対象となるアプリケーション。

Android端末がNativeDriverリクエストを受け付ける準備

※近い将来これらのステップはソースコードに埋め込まれるでしょう。恐らくAdbConnection classを拡張したものを使います。
と書かれているのでこの作業は今だけかも。

  1. instrumentationを伴ったアプリケーションをリスタートさせる
adb shell am instrument com.google.android.testing.nativedriver.simplelayouts/com.google.android.testing.nativedriver.server.ServerInstrumentation

NativeDriverのServerInstrumentationクラスはJSON Wire Protocolのデバイスポートで稼働するリクエストを待ち受けています。JSON Wire ProtocolはSelenium WebDriverで使われているプロトコルとほぼ同等のものです。

  1. ポートフォワーディングを有効にする

これはNativeDriverクライアントがノーマルなTCP通信を通じて端末にアクセスできるようにするためです。

adb forward tcp:54129 tcp:54129

instrumentationがスタートしてるか確認。

I/com.google.android.testing.nativedriver.server.ServerInstrumentation(  273): Jetty started on port 54129

テスト

  • android-testの3つのうちのひとつを右クリック
  • Run As->JUnit Test
  • Eclipse JUnit Launcher as the Preferred Launcher を選択
  • バイススクリーン見てみて!