大家好,我在创建测试工程后,编写一个测试用例,已经导入 robotium-solo-5.2.1.jar 包,且代码中使用的包名和类名均正确,在执行其中的一个 testCase 时,提示找不到类的异常,如下所示:
Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'‘;
我使用了很多网络上的操作,比如确定启动类 “LAUNCHER_ACTIVITY_FULL_CLASSNAME” 是否正确,导入 junit4 等,
但是问题还是没有办法得到解决,因为之前在执行一样的代码都是可以正常运行的,不会出现这个提示。
想问一下,是否有对设置场景的遗漏导致的呢?大家有没有遇到类似的错误提示呢?谢谢!
代码如下:
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.*;

public class CaiYinLibraryTest extends ActivityInstrumentationTestCase2 {

private Solo solo;
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="xxxxx";
private static String packageName="xxxxxxxx";
private static Class<?> launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings({ "unchecked", "deprecation" })
public CaiYinLibraryTest() throws ClassNotFoundException{
super(packageName,Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME));
}
@Override
@Before
public void setUp() throws Exception {
solo=new Solo(getInstrumentation());
getActivity();
}

@Override
@After
public void tearDown() throws Exception {
try {
solo.finishOpenedActivities();// 解决执行多个用例时出现卡住的问题
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}

@Test
public void testDetail() {
solo.sleep(2000);
solo.getCurrentActivity();

RelativeLayout parentView = (RelativeLayout) solo.getView("pic_lick_num_id").getParent();
LinearLayout linearlayout=(LinearLayout) parentView.findViewById(1);
linearlayout.getChildAt(0);
solo.clickOnView(solo.getView("gallery_flower_btn"));

}
}


↙↙↙阅读原文可查看相关链接,并与作者交流