リア充爆発日記

You don't even know what ria-ju really is.

RobolectricでActionBarSherlockのテストをしようとしてNo implementations match configuration

java.lang.IllegalStateException: No implementations match configuration.

もうそろそろ普通に開発させてくれんかね。。

で、タウンページをめくってみるとABS本家のgithubが筆頭に。
https://github.com/JakeWharton/ActionBarSherlock/issues/377

When ActionBarSherlock looks for an implementation, it bases the decision on the Build.VERSION.SDK_INT constant. When running tests using Robolectric, this constant is set to zero, which means no implementation will be found and an exception is thrown:

これが理由。

で、開発者本人が解決策(コード)置いてってくれてる。

・・・あれだね。この人短気だね。どうしても困ったときに質問するとけっこう答えて貰えるAndroidIRCチャンネルがあって、英語の勉強もかねていつもそこ開いてるんだけど(ドヤァ、この人そこにときどき降臨するのね。やっぱり短気な感じするね。

これとかワラタ。っていうかSquareの人なのね。
https://gist.github.com/3803294
↑コレは結局よくわからなかったので使わなかった
Robolectric、悪くないと思うんだけどね。っていうかグーグルがちゃんとだせよ、テストツール

。。。で、これを適当なところにおいて
ActionBarSherlockRobolectric.java

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.internal.ActionBarSherlockNative;
import com.xtremelabs.robolectric.Robolectric;

@ActionBarSherlock.Implementation(api = 0)
public class ActionBarSherlockRobolectric extends ActionBarSherlockNative {
    public ActionBarSherlockRobolectric(Activity activity, int flags) {
        super(activity, flags);
    }

    @Override 
    public void setContentView(int layoutResId) {
        LayoutInflater layoutInflater = LayoutInflater.from(mActivity);
        View contentView = layoutInflater.inflate(layoutResId, null);

        Robolectric.shadowOf(mActivity).setContentView(contentView);
    }

    @Override 
    public void setContentView(View view) {
        Robolectric.shadowOf(mActivity).setContentView(view);
    }
}

テストクラスで

    @BeforeClass
    public static void init() {
        ActionBarSherlock.registerImplementation(ActionBarSherlockRobolectric.class);
    }

こんな感じ?

っていうかさー、RobolectricはサンプルのRoboGuice古いし、RoboGuiceはドキュメントがからっきしだし、バージョン違いでの差分でかいし、マジきついわー。


前に開発なんて6割読書だよ、みたいなことを適当に書いたけど、ここ一週間9割くらいはタウンページめくってるよ。。。
ヨシズミが欲しいわー。