测试运行失败:由于'java.lang.ClassNotFoundException,检测运行失败

时间:2013-10-10 22:14:39

标签: robotium

我创建了一个简单的项目来在模拟器上启动facebook app。运行程序时,将显示以下错误  测试运行失败:由于'java.lang.ClassNotFoundException

,检测运行失败

代码是fb.java文件

  package com.facebook.katana;

  import junit.framework.Assert;
  import com.jayway.android.robotium.solo.Solo;
  //import junit.framework.Assert;
  import android.test.ActivityInstrumentationTestCase2;

   @SuppressWarnings("rawtypes")
   public class fb extends ActivityInstrumentationTestCase2{

     private Solo solo;
     private static final String TARGET_PACKAGE_ID ="com.facebook.katana";  
     private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.facebook.katana.LoginActivity";    
     private static Class<?> launcherActivityClass; 
     static{    
         try{   
             launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);   
         } catch(ClassNotFoundException e) {    
             throw new RuntimeException(e); 
         }  
     }  

    @SuppressWarnings({ "unchecked", "deprecation" })
    public fb() {
        super(TARGET_PACKAGE_ID, launcherActivityClass);
        // TODO Auto-generated constructor stub
      }

   @Override
   protected void setUp() throws Exception{ 
       solo = new Solo(getInstrumentation(), getActivity());
   }    

   public void testCanOpenSettings() throws InterruptedException{   

           // wait for the specified time
       solo.sleep(3000);

       solo.clearEditText(0);

       solo.enterText(0, "abc@abc");
       // wait for the specified time 
       solo.sleep(3000);

      solo.enterText(1, "acd");

      solo.sleep(3000);

   }

   private boolean assertTrue(Object clickOnImage) {
       // TODO Auto-generated method stub
       return false;
   }

   @Override
   public void tearDown() throws Exception{ 
       try{ 
       solo.finalize(); 
       } catch(Throwable e) {   
           e.printStackTrace(); 
       }    
       getActivity().finish();  
       super.tearDown();        
   }  
}

清单。 xml文件(FB2 Manifest.xml)

    <?xml version="1.0" encoding="utf-8"?>
     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.facebook.katana.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="18" />

   <instrumentation
       android:name="android.test.InstrumentationTestRunner"
       android:targetPackage="com.facebook.katana" />
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
      android:icon="@drawable/ic_launcher"
       android:label="@string/app_name" >
      <uses-library android:name="android.test.runner" />
    </application>

  </manifest>

请帮助解决此问题

1 个答案:

答案 0 :(得分:1)

指定的启动者活动全类名称不正确。 将此设置为正确的活动名称后,程序执行成功。