私のセットアップ:
- ライブラリプロジェクト:ActionBarSherlock
- 計画
- テストプロジェクト
私のプロジェクトには、ライブラリプロジェクトがライブラリプロジェクトとしてリンクされています。コンパイルして正常に実行されます。
ここで、通常のテストプロジェクトを使用してアプリケーションをテストしようとしています。Eclipseでテストを実行すると完璧に機能します。antを使用してテストを実行しようとすると、テストプロジェクトはコンパイルされません。
[javac] LoginActivityTest.java:9: cannot access com.actionbarsherlock.app.SherlockActivity
[javac] class file for com.actionbarsherlock.app.SherlockActivity not found
[javac] public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
[javac] ^
[javac] LoginActivityTest.java:25: cannot find symbol
Eclipseによる構築は完璧に機能し、テストも完璧に実行されます。
ライブラリプロジェクトをテストプロジェクトにリンクすると、antでコンパイルされますが、テストは失敗します。
[exec] Error in testSuiteConstructionFailed:
[exec] java.lang.RuntimeException: Exception during suite construction
[exec] at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
[exec] at java.lang.reflect.Method.invokeNative(Native Method)
[exec] at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
[exec] at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
[exec] at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
[exec] at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
[exec] Caused by: java.lang.reflect.InvocationTargetException
[exec] at java.lang.reflect.Constructor.constructNative(Native Method)
[exec] at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
[exec] at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
[exec] at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
[exec] at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
[exec] at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
[exec] at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:371)
[exec] at com.zutubi.android.junitreport.JUnitReportTestRunner.onCreate(JUnitReportTestRunner.java:90)
[exec] at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3891)
[exec] at android.app.ActivityThread.access$1300(ActivityThread.java:122)
[exec] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
[exec] at android.os.Handler.dispatchMessage(Handler.java:99)
[exec] at android.os.Looper.loop(Looper.java:137)
[exec] at android.app.ActivityThread.main(ActivityThread.java:4340)
[exec] at java.lang.reflect.Method.invokeNative(Native Method)
[exec] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
[exec] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
[exec] at dalvik.system.NativeStart.main(Native Method)
[exec] Caused by: java.lang.NoClassDefFoundError: com.myproject.android.app.activities.LoginActivity
[exec] at com.myproject.android.app.test.LoginActivityTest.<init>(LoginActivityTest.java:18)
[exec] ... 19 more
私のテストクラス:
public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
private LoginActivity mActivity;
private EditText mTextUserName;
private EditText mTextUserPassword;
public LoginActivityTest() {
// the super call is line 18 (see stack trace above)
super("com.myproject.android.app.activities", LoginActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
mTextUserName = (EditText) mActivity.findViewById(com.myproject.android.app.R.id.login_activity_username);
mTextUserPassword = (EditText) mActivity.findViewById(com.myproject.android.app.R.id.login_activity_password);
}
public void testPreConditions() {
assertTrue("Activity is null!", mActivity != null);
}
public void testLogin() throws Throwable {
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextUserName.setText("username");
mTextUserPassword.setText("password");
}
});
sendKeys(KeyEvent.KEYCODE_ENTER);
}
}
これを修正する方法はありますか?
更新:antのビルド/テストはまだ混乱しているようです。ライブラリプロジェクトのテストに関するこのブログエントリによると、リストされている7つの問題のほとんどは、次のADTリリース(ADT r20)で修正される予定です。