我正在尝试JUnit测试,但面临以下问题。
当我通过右键单击Project选择Android JUnit Test时,它会显示以下消息
测试运行失败:由于本机崩溃'
导致仪表运行失败
当我右键单击TestApk.java并选择Android JUnit Test时,它会显示
测试运行失败:由于java.lang.ClassNotFoundException
,检测运行失败
发生两种情况
这是我的源代码。
@SuppressWarnings("unchecked")
public class TestApk extends ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.nhn.android.ndrive";
private static Class launcherActivityClass;
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public TestApk() throws ClassNotFoundException {
super(launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void testDisplayBlackBox() {
//Enter any integer/decimal value for first editfield, we are writing 10
solo.clickOnWebElement(By.id("com.nhn.android.ndrive:id/actionbar_photo_left_button"));
solo.clickOnWebElement(By.id("com.nhn.android.ndrive:id/gnb_group_layout"));
//Enter any integer/decimal value for first editfield, we are writing 20
solo.clickOnWebElement(By.id("com.nhn.android.ndrive:id/actionbar_open_drawer_button"));
//Click on Multiply button
solo.clickOnButton("com.nhn.android.ndrive:id/base_menu_task_open_button");
//Verify that resultant of 10 x 20
//assertTrue(solo.searchText("200"));
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
但包名没有错。
如何解决这个问题?