51Testing软件测试论坛

标题: 求Robotium大神解决一下这个新手问题啊 [打印本页]

作者: Conrad    时间: 2015-1-8 09:14
标题: 求Robotium大神解决一下这个新手问题啊
[2015-01-08 09:26:19 - NotePadTest] ------------------------------
[2015-01-08 09:26:19 - NotePadTest] Android Launch!
[2015-01-08 09:26:19 - NotePadTest] adb is running normally.
[2015-01-08 09:26:19 - NotePadTest] Performing android.test.InstrumentationTestRunner JUnit launch
[2015-01-08 09:26:19 - NotePadTest] Automatic Target Mode: using device 'bb75902e'
[2015-01-08 09:26:19 - NotePadTest] Uploading NotePadTest.apk onto device 'bb75902e'
[2015-01-08 09:26:20 - NotePadTest] Installing NotePadTest.apk...
[2015-01-08 09:26:22 - NotePadTest] Success!
[2015-01-08 09:26:22 - NotePadTest] Project dependency found, installing: NotePad
[2015-01-08 09:26:23 - NotePad] Application already deployed. No need to reinstall.
[2015-01-08 09:26:23 - NotePadTest] Launching instrumentation android.test.InstrumentationTestRunner on bb75902e
[2015-01-08 09:26:24 - NotePadTest] Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
百度里面的原因我都排查了一下 ,都不是呀  。。我按照视频写的代码  一模一样都会这样报错。

作者: lsekfe    时间: 2015-1-8 09:18
建议你把问题描述的清晰一点。。。
作者: Conrad    时间: 2015-1-8 10:10
lsekfe 发表于 2015-1-8 09:18
建议你把问题描述的清晰一点。。。

就是用Robotium框架写了一个关于eclipse自带例子NotePad的测试用例,测试用例代码如下:
package com.example.android.notepad.test;
import junit.framework.Assert;
import com.robotium.solo.Solo;
import android.app.Activity;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class NotePadTest extends ActivityInstrumentationTestCase2 {
private static final String Launcher_Avtivity_Full_ClassName = "com.example.android.notpad.NotesList";
    private static Class<?> launcherActivityClass;
    private Solo solo;
    private Activity activity;
    private Instrumentation inst;
   
    static {
     try{
      launcherActivityClass = Class.forName(Launcher_Avtivity_Full_ClassName);
     }catch (ClassNotFoundException e){
      throw new RuntimeException(e);
     }
    }
public NotePadTest() {
  super(launcherActivityClass);
}
protected static void setUpBeforeClass() throws Exception {
}
protected static void tearDownAfterClass() throws Exception {
}
public Activity getActivity(){
  return super.getActivity();
}

protected void setUp() throws Exception {
  inst = getInstrumentation();
  solo = new Solo(inst,getActivity());
  super.setUp();
}
protected void tearDown() throws Exception {
  solo.finishOpenedActivities();
  super.tearDown();
}
public void testAddNote(){
  solo.sleep(3000);
  View menuadd = solo.getView("menu_add");
  solo.clickOnView(menuadd);
  solo.sleep(2000);
  solo.enterText(0, "Note1");
  solo.sleep(2000);
  View menusave = solo.getView("menu_save");
  solo.clickOnView(menusave);
  ListView list = (ListView)solo.getView("list");
  TextView tv = (TextView)solo.getView("tv");
  Assert.assertEquals(true, tv.getText().equals("Note1"));
}
public void testdeleteNote(){
        ListView list  = (ListView)solo.getView("list");
        int beforecount = list.getChildCount();
        Log.d("debug", "beforeCount:"+beforecount);
        solo.sleep(2000);
        solo.clickOnView(list.getChildAt(0));
        solo.clickOnText("delete");
        solo.sleep(3000);
        int aftercount = list.getChildCount();
        Log.d("debug", "beforeCount:"+aftercount);
        Assert.assertEquals("删除笔记后数目没有减少", 1,beforecount-aftercount);
    }
}

Run as android JUnit Test控制台就会报这个错误:
Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'。

作者: lsekfe    时间: 2015-1-8 13:01
Conrad 发表于 2015-1-8 10:10
就是用Robotium框架写了一个关于eclipse自带例子NotePad的测试用例,测试用例代码如下:
package com.ex ...

从代码上看,感觉上是冲突了。你仔细看下~
作者: gaojie1234    时间: 2016-6-16 21:02
楼主解决了么?我也遇到同样问题。。已经解决的话能指点一下么?谢谢~




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2