我正在尝试运行我的第一个 android 测试
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.Button;
import com.lenabru.activities.MainActivity;
/**
* @author Lena Sep 16, 2013, 2013 at 10:02:19 PM
*/
public class MainActivityUnitTest extends ActivityUnitTestCase<MainActivity> {
MainActivity activity;
int buttonId;
public MainActivityUnitTest() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
Intent intent = new Intent(getInstrumentation().getTargetContext(), MainActivity.class);
startActivity(intent, null, null);
activity = getActivity();
}
@SmallTest
public void testLayout() {
buttonId = com.lenabru.R.id.btnLogin;
assertNotNull(activity.findViewById(buttonId));
Button view = (Button) activity.findViewById(buttonId);
assertEquals("Incorrect label of the button", "Start", view.getText());
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}
但是,我得到了这个例外
junit.framework.AssertionFailedError: Exception in constructor: testLayout (java.lang.NoClassDefFoundError: com.lenabru.ichess.activities.MainActivity
at com.lenabru.test.MainActivityUnitTest.<init>(MainActivityUnitTest.java:26)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:103)
at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:127)
at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:55)
at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:81)
at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:418)
at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:399)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:364)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3369)
at android.app.ActivityThread.access$2200(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1006)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
如何解决?