2014-10-05 5 views
1

에스프레소를 사용하여 활동 테스트를하고 싶지만 NoClassDefFoundError가 표시됩니다 (아래에 스택 참조). 나는에 유래에서 본 몇 가지를 시도했지만 아무도 나를 위해 일하지NoClassDefFoundError (에스프레소를 사용하여 활동 테스트 중)

10-04 23:18:28.901 13845-13845/com.example.test E/dalvikvm﹕ Could not find class 'com.example.test.ui.SplashActivity', referenced from method com.example.test.test.ui.SplashActivityTest.<init> 
10-04 23:18:28.901 13845-13845/com.example.test W/dalvikvm﹕ VFY: unable to resolve const-class 2480 (Lcom/example/test/ui/SplashActivity;) in Lcom/example/test/test/ui/SplashActivityTest; 
10-04 23:18:28.901 13845-13845/com.example.test D/dalvikvm﹕ VFY: replacing opcode 0x1c at 0x0000 
10-04 23:18:28.901 13845-13858/com.example.test I/TestRunner﹕ started: warning(junit.framework.TestSuite$1) 
10-04 23:18:28.911 13845-13845/com.example.test I/GoogleInstr﹕ Activities that are still in CREATED to PAUSED: 0 
10-04 23:18:28.911 13845-13858/com.example.test I/TestRunner﹕ failed: warning(junit.framework.TestSuite$1) 
10-04 23:18:28.911 13845-13858/com.example.test I/TestRunner﹕ ----- begin exception ----- 
10-04 23:18:28.911 13845-13858/com.example.test I/TestRunner﹕ junit.framework.AssertionFailedError: Exception in constructor: testNextActivityWasLaunchedWithIntent (java.lang.NoClassDefFoundError: com.example.test.ui.SplashActivity 
      at com.example.test.test.ui.SplashActivityTest.<init>(SplashActivityTest.java:21) 
      at java.lang.reflect.Constructor.constructNative(Native Method) 
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
      at junit.framework.TestSuite.createTest(TestSuite.java:61) 
      at junit.framework.TestSuite.addTestMethod(TestSuite.java:294) 
      at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150) 
      at junit.framework.TestSuite.<init>(TestSuite.java:129) 
      at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118) 
      at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:149) 
      at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:57) 
      at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80) 
      at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:443) 
      at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:424) 
      at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370) 
      at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114) 
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4319) 
      at android.app.ActivityThread.access$1500(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5001) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
      at dalvik.system.NativeStart.main(Native Method) 
    ) 
      at junit.framework.Assert.fail(Assert.java:50) 
      at junit.framework.TestSuite$1.runTest(TestSuite.java:97) 
      at junit.framework.TestCase.runBare(TestCase.java:134) 
      at junit.framework.TestResult$1.protect(TestResult.java:115) 
      at junit.framework.TestResult.runProtected(TestResult.java:133) 
      at junit.framework.TestResult.run(TestResult.java:118) 
      at junit.framework.TestCase.run(TestCase.java:124) 
      at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) 
      at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) 
      at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) 
      at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167) 
      at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701) 

내 빌드 스크립트 :

buildscript { 
    dependencies { 
     repositories { 
      mavenCentral() 
     } 

     classpath 'com.android.tools.build:gradle:0.12.+' 
     classpath 'com.github.jcandksolutions.gradle:android-unit-test:1.6.2' 
    } 
} 

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 20 
    buildToolsVersion "20.0.0" 

    defaultConfig { 
     applicationId "com.example.test" 
     minSdkVersion 15 
     targetSdkVersion 20 
     versionCode 1 
     versionName "1.0" 
     applicationId "com.example.test" 

     testApplicationId "com.example.test" 
     testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
     testHandleProfiling true 
     testFunctionalTest true 
    } 

    buildTypes { 
     release { 
      runProguard false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 

     debug { 
      testCoverageEnabled = true 
     } 
    } 

    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/ASL2.0' 
     exclude 'LICENSE.txt' 
    } 

    lintOptions { 
     abortOnError false 
     ignoreWarnings true 
    } 


} 

apply plugin: 'android-unit-test' 
apply plugin: 'jacoco' 

jacoco { 
    toolVersion = "0.7.1.201405082137" 
} 

def coverageSourceDirs = [ 
     '../app/src/main/java' 
] 

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") { 
    group = "Reporting" 

    description = "Generate Jacoco coverage reports" 

    classDirectories = fileTree(
      dir: '../app/build/intermediates/classes/debug', 
      excludes: ['**/R.class', 
         '**/R$*.class', 
         '**/*$ViewInjector*.*', 
         '**/BuildConfig.*', 
         '**/Manifest*.*'] 
    ) 

    additionalSourceDirs = files(coverageSourceDirs) 
    sourceDirectories = files(coverageSourceDirs) 
    executionData = files('../app/build/jacoco/testDebug.exec') 

    reports { 
     xml.enabled = true 
     html.enabled = true 
    } 

} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.google.android.gms:play-services:5.2.08' 
    compile 'com.android.support:appcompat-v7:20.+' 


    androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r3') { 
     exclude group: 'org.hamcrest', module: 'hamcrest-integration' 
    } 
    androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { 
     exclude group:'com.android.support' 
     exclude group: 'org.hamcrest', module: 'hamcrest-integration' 
    } 
} 

답변

1

당신은 testApplicationId "com.example.test" 의도적, 거기에 "테스트하지 않아야한다는 것이다있다 "suffix :

totestApplicationId "com.example.test.test"

+0

정확하게 그랬습니다. testApplicationId를 applicationId와 동일한 값으로 설정했습니다. – Akeem

관련 문제