2012-07-06 1 views
2

나는 안드로이드 유닛 테스팅과 함께 꽂아 왔고 경로 문제로 보이는 것을 만났습니다.안드로이드 유닛 테스트 패키지 경로 오류

먼저 내 프로젝트 디렉터리

android create test-project -m ../ -p tests -n RoamPayTests 

이 테스트 프로젝트를 생성하고 그것을 초기화 내에 내에서이 명령을 실행합니다. 자동 생성 ActivityInstrumentaionTestCase2가 정상적으로 작동합니다. 여기에서 테스트를 만들 수 있으며 모든 것이 작동합니다.

참고 : 주 활동은 UI 패키지에 있습니다. 여기

package com.roamdata.roampayx; 

import com.roamdata.roampayx.ui.SplashActivity; 

import android.test.ActivityInstrumentationTestCase2; 

/** 
* This is a simple framework for a test of an Application. See 
* {@link android.test.ApplicationTestCase ApplicationTestCase} for more information on 
* how to write and extend Application tests. 
* <p/> 
* To run this test, you can type: 
* adb shell am instrument -w \ 
* -e class com.roamdata.roampayx.ui.SplashActivityTest \ 
* com.roamdata.roampayx.tests/android.test.InstrumentationTestRunner 
*/ 
public class SplashActivityTest extends ActivityInstrumentationTestCase2<SplashActivity> { 

    public SplashActivityTest() { 
     super("com.roamdata.roampayx", SplashActivity.class); 
    } 

내가 새로운 테스트 케이스를 만들려고 할 때 문제가 Android_Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us --> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="com.roamdata.roampayx.tests" 
      android:versionCode="1" 
      android:versionName="1.0"> 
    <!-- We add an application tag here just so that we can indicate that 
     this package needs to link against the android.test library, 
     which is needed when building test cases. --> 
    <application> 
     <uses-library android:name="android.test.runner" /> 
    </application> 
    <!-- 
    This declares that this application uses the instrumentation test runner targeting 
    the package of com.roamdata.roampayx. To run the tests use the command: 
    "adb shell am instrument -w com.roamdata.roampayx.tests/android.test.InstrumentationTestRunner" 
    --> 
    <instrumentation android:name="android.test.InstrumentationTestRunner" 
        android:targetPackage="com.roamdata.roampayx" 
        android:label="Tests for com.roamdata.roampayx"/> 
</manifest> 

생성 된 자동입니다.

package com.roamdata.roampayx; 
import com.roamdata.roampayx.provider.RoamPay; 
import com.roamdata.roampayx.provider.RoamPayProvider; 
import android.test.ProviderTestCase2; 


public class ProviderTest extends ProviderTestCase2<RoamPayProvider> { 
    public ProviderTest() { 
     super(RoamPayProvider.class, RoamPay.AUTHORITY); 
    } 
} 

다음으로 빌드하고 설치합니다 (여기에는 문제 없음). 그러나 나는

adb shell am instrument -w com.roamdata.roampayx.tests/android.test.InstrumentationTestRunner 

을 실행 그리고 마침내 나는 다음과 같은 오류

android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests: 
Error in testSuiteConstructionFailed: 
java.lang.RuntimeException: Exception during suite construction 
    at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) 
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) 
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) 
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584) 
Caused by: java.lang.reflect.InvocationTargetException 
    at java.lang.reflect.Constructor.constructNative(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
    at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87) 
    at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73) 
    at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262) 
    at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184) 
    at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4142) 
    at android.app.ActivityThread.access$1300(ActivityThread.java:130) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4745) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
    at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: com.roamdata.roampayx.provider.RoamPayProvider 
    at ProviderTest.<init>(ProviderTest.java:9) 
    ... 18 more 

내가 RoamPay 및 RoamPayProvider의 수입을 얻을. 인텔리 센스가 작동 중이고 그 참조가 나타납니다.

아이디어가 있으십니까?

답변

1

모든 것은 생성자를 제외하고는 훌륭했습니다. 나는 이것을

public RoamPayProviderTest() { 
    super(RoamPayProvider.class, "com.roamdata.roampayx"); 
} 

으로 바 꾸었습니다. 이제 모든 것이 작동합니다. 이 질문과 답변을 사용하여 단위 테스트를 설정하는 방법에 대한 좋은 자습서로 사용할 수 있습니다.

+0

왜 여기에 패키지 이름을 포함 시켰습니까? –