Androi Espresso Intent.ACTION_GET_CONTENTのテスト

Android
Espresso

ファイルを選択して、その名称を表示するActivityのテストです。
Intent.ACTION_GET_CONTENTを使って、ファイル選択のダイアログを表示し、ファイルを選択して、その名称が表示されているかどうかというテストです。

※ちょっとしょっぱいことに、ファイル選択のダイアログ表示→そのあとファイルを選択する、というところまでは、自動化できませんでした(^_^;

この記事と
https://codelabs.developers.google.com/codelabs/android-testing/index.html?index=..%2F..%2Findex&hl=ja#7

こちらのStack Overflowを参考に
http://stackoverflow.com/questions/32142463/how-to-stub-select-images-intent-using-espresso-intents

作成しています。

 @RunWith(AndroidJUnit4.class)
 @LargeTest
 public class AddFileToRegisterTest {
 
    public static final String FACE_PHOTO_PATH = "/storage/emulated/0/Download/スクリーンショット-2015-07-16-23.37.54.png";
    public static final String FACE_PHOTO_NAME = "スクリーンショット-2015-07-16-23.37.54.png";
 
    @Rule
    public IntentsTestRule<RegisterActivity> mRegisterIntentsTestRule =
            new IntentsTestRule<>(RegisterActivity.class);
 
    @Before
    public void registerIdlingResource() {
        Espresso.registerIdlingResources(
                mRegisterIntentsTestRule.getActivity().getCountingIdlingResource());
    }
 
   @Test
    public void activityResult_IsHandledProperly() {
        // Build a result to return when a particular activity is launched.
        Bundle bundle = new Bundle();
        ArrayList<Parcelable> parcels = new ArrayList<>();
        Intent resultData = new Intent();
        Uri uri1 = Uri.parse("file:/" + FACE_PHOTO_PATH);
        Parcelable parcelable1 = (Parcelable) uri1;
        parcels.add(parcelable1);
        bundle.putParcelableArrayList(Intent.EXTRA_STREAM, parcels);
        // Create the Intent that will include the bundle.
        resultData.putExtras(bundle);
        Instrumentation.ActivityResult result = createImageCaptureActivityResultStub();
 
        intending(allOf(
                hasAction(equalTo(Intent.ACTION_GET_CONTENT))
         )).respondWith(result);
 
        // User action that results in "contacts" activity being launched.
        // Launching activity expects phoneNumber to be returned and displays it on the screen.
        onView(withId(R.id.last_name)).perform(closeSoftKeyboard());
        onView(withId(R.id.face_photo_upload)).perform(scrollTo()).perform(click());
 
 
        onView(withId(R.id.face_photo_title))
                .perform(scrollTo()) // Scroll to thumbnail
                .check(matches(withText(FACE_PHOTO_NAME)));
 
    }
 
      /**
     * Unregister your Idling Resource so it can be garbage collected and does not leak any memory.
     */
    @After
    public void unregisterIdlingResource() {
        Espresso.unregisterIdlingResources(
                mRegisterIntentsTestRule.getActivity().getCountingIdlingResource());
    }
 
    private Instrumentation.ActivityResult createImageCaptureActivityResultStub() {
        // Create the ActivityResult, with a null Intent since we do not want to return any data
        // back to the Activity.
        return new Instrumentation.ActivityResult(Activity.RESULT_OK, null);
    }
 }

ハマったことは

 intending(allOf(
                hasAction(equalTo(Intent.ACTION_GET_CONTENT))
         )).respondWith(result);

が、どうしても中身がNullになって、ヌルポで落ちてしまうことです。

答えは、Espressoさんの公式サイトに書いてありました!
Espresso-Intentsを利用するときは、IntentsTestRulを使えということだそうです。

いつものことですけどね、ちゃんとドキュメントは読むように!ってことですね。。。

IntentsTestRule

Use IntentsTestRule instead of ActivityTestRule when using Espresso-Intents. IntentsTestRule makes it easy to use Espresso-Intents APIs in functional UI tests. This class is an extension of ActivityTestRule, which initializes Espresso-Intents before each test annotated with @Test and releases Espresso-Intents after each test run. The activity will be terminated after each test and this rule can be used in the same way as ActivityTestRule.

    @Rule
    public IntentsTestRule<RegisterActivity> mRegisterIntentsTestRule =
            new IntentsTestRule<>(RegisterActivity.class);

Andoroid SDKの中のサンプルプログラムの一覧

Android

Andoroid SDKの中のサンプルプログラムの一覧

Android SDKのフォルダの中に、Googleが作ってくれているサンプルプログラムがあります。
中身をみると、非常に勉強になるのですが、そもそもフォルダ名を見ればわかるアプリもあれば、そうでないアプリもあります。
どっかに一覧ないの~?と思っていたら、ここにありました。

http://jayxie.com/mirrors/android-sdk/resources/samples/index.html

よかったよぉ~ よかったねぇ~(^_^)

Andorid Google MapがGoogle Playに載せたら表示されない

Android

Andorid Google MapがGoogle Playに載せたら表示されない

ローカル環境でデバッグや、テスト機ではOKだったのに、Google Playにアップロードした後はGoogle Mapが表示されない、という場合、Google MapのAPIが、デバッグ用のキーになってないか確認してみましょう。

証明書を使ってサインした後も、テスト機でテストする必要がありますね(^_^;

An unknown error occurred

Xcode
実機テストで、ビルドする際、
「An unknown error occurred」というエラーが発生し、ビルドすらしない場合はXcodeのDerived Dataを削除するとうまくいく場合がある。
Derived DataはXcodeのキャッシュなのでフォルダの中身をまるごと削除してしまって構わない。
/Users/[ユーザー名]/Library/Developer/Xcode/DerivedData
に存在する。

Amazon Product Advertising API パラメーターとカテゴリの組み合わせ

PHP

Amazon Product Advertising API パラメーターとカテゴリの組み合わせ

Amazon Product Advertising API はじめの一歩に書きましたように、Amazonにリクエストを送って、結果が帰ってくるようになりました。

ですが、またもや悩ましい問題がっ!

Amazon Product Advertising APIでは、製品のカテゴリーによって、検索条件に入れられるもの、入れられないものが複雑に決まっているのです。

その一覧が下記。
http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/JPSearchIndexParamForItemsearch.html#JPSearchIndexParamForItemsearch_Watches

大体の人が、買い物する時に参考にしたいのは金額だと思いますから、金額に話を絞りますと、たとえばApparelにカテゴリを指定すると、最低金額、最高金額での絞り込みができません。
ElectronicsやJewelryも同様です。
Watchesは、MinimumPriceしか指定できません。

上記のカテゴリーを見ると、高額商品のカテゴリーなので、転売に使われないようにしている、ということでしょうか…。
なんかこういう細工はやめて頂きたいですけどねぇ。。。