この問題を抱えているのは私だけではないことがわかりましたが、正しい答えが見つかりません。テストしたいAndroidプロジェクトがあります。プロジェクトのクラスごとに junit テスト クラスを作成します。私の問題は、テストを実行すると、次のエラーが発生することです。
java.lang.NoClassDefFoundError: android/content/Context
これは私のクラスのテストです:
public class DevicesBDDTest extends TestCase {
DevicesBDD bdd;
/**
* @throws java.lang.Exception
*/
protected static void setUpBeforeClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
protected static void tearDownAfterClass() throws Exception {
}
protected void setUp() throws Exception {
super.setUp();
Context ctx = mock(Context.class);
final MaBaseSQLiteInterface mockMaBaseSQLite = mock(MaBaseSQLiteInterface.class);
bdd = new DevicesBDD(ctx){
@Override
public MaBaseSQLiteInterface createMaBaseSQlite(Context context) {
return mockMaBaseSQLite;
}
};
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void test() {
assertEquals(1, 1);
}
}
私のクラス DevicesBDD にはオブジェクト Context が必要なので、(mockito を使用して) モックを作成します。オブジェクト MockContext も試しましたが、うまくいきません。
これは私のJavaビルドパスです:
- mockito-all-1.9.5.jar
- Android 2.1 -> android.jar
- Android の依存関係 -> annotations.jar
- Junit 3 -> junit.jar