/var/log/messages

Nov 8, 2013 - 2 minute read - Comments - android

Hello World な Espresso の試験を書いてみる

おそらく試験にパスしないですが記録を残すという意味で GitHub 方面にもソース登録の方向です。とりあえずハロワなプロジェクトを作成。

以下な属性ってことで。

  • API15 限定
  • こちらの修正点としては res/layout/activity_main.xml について HelloWorld な TextView に id を付与するのみ

で、試験なプロジェクトを作るのか。つうか このエントリから jar が取得できなくて辛い。以下から取得したのですがどうなんでしょ。

で、解凍して bin の中にある jar を新規作成した試験プロジェクトの libs の中に投入。試験なプロジェクトの AndroidManifest を修正して

    <instrumentation
        android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
        android:targetPackage="com.example.helloworld" />

あと、試験なクラスを追加しないといけないですね。

  • HelloWorldTest という ActivityInstrumentationTestCase2 を継承したクラスを作成

  • コンストラクタを追加

      public HelloWorldTest() {
          super(MainActivity.class);
      }
    

で、試験を追加すりゃ良いのか。

Run - Run Configration から作った試験が出てこない、と思ったら Android JUnit Test をクリックして新規作成したら出てきた。Manifest で指定したソレを Instrumentation runner に指定してとりあえず apply しておく。

試験追加します。以下で良いのかどうか。

package com.example.helloworld.test;

import com.example.helloworld.MainActivity;

import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions;
import com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers;

import android.test.ActivityInstrumentationTestCase2;

public class HelloWorldTest extends ActivityInstrumentationTestCase2<MainActivity> {
	
    public HelloWorldTest() {
        super(MainActivity.class);
    }

    public void testHelloWorld() {
        onView(ViewMatchers.withId(com.example.helloworld.R.id.helloworld))
            .check(ViewAssertions.matches(ViewMatchers.withText("Hello World!")));
    }
}

実行してみた

emulator が出てきたぞ。もしかして前回微妙だったのはこのあたりが原因なのかな。 ちなみに実機接続して実行してみると前回と同じ現象。ちょっとだけ前進してはいるのでしょうが、根本的な原因がナニ。

で、emulator を起動してみたんですが動く気配がない。ここで一旦エントリ入れて GitHub 方面にアレしたりする方向にて。 て先に登録しますね。今の時点なナニを登録したリポジトリは以下です。

今日はこれで終了。

Octopress の TODO FSF に donate しようず、って言って

comments powered by Disqus