2014-04-26 3 views
2

저는 안드로이드 스튜디오에서 Robolectric을 만들려고 여러 시간을 보냈지만, 성공하지 못했습니다. 그리고 나는 거의 포기할 것입니다. 다음과 같은 오류가 발생합니다 :Android Studio에서 Robolectric을 실행하는 방법은 무엇입니까?

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!

물론 저는 3.8 (4.11, 참으로)보다 새로운 junit 버전을 사용합니다.

  • 이 같은 변화로 Gradle을 트릭을 시도,

    • 이동 어딘가에 제안 최초의 하나가 될 수있는 JUnit을 의존성 : 나는 몇 가지 트릭을 시도했습니다

      같은이 관련된 다른 질문에 세운 내 Android Studio 버전 (0.5.7)에 포함 된 Gradle 버전이 이 인식하지 못하는 것 같지만 instrumentTestCompile, apply plugin을 'android-unit-test'sourceSets.instrumentationtest.setRoot, classpath, dependencies -> 태그.

    심지어 심지어 컴파일하지 않는 GitHub의 예제를 다운로드했습니다. 그래서 나는 이것에 정말로 지쳤습니다.

    아이디어가 있으십니까?

    답변

    1

    This run will fail with a complaint about “JUnit version 3.8 or later expected”. The reason for this is that jUnit 4 is too far down the classpath, and now comes perhaps the least elegant part of this setup: as Kostya Y explains, copy the whole contents of the console with the error message into a text editor and do this:

    1. Remove everything except -classpath “…”
    2. Move jUnit 4 to be the first thing in the classpath
    3. Add an entry for the absolute path to the robolectric test classes directory as the last item in the classpath, in this case /path/to/MyProject/app/build/classes/robolectric.

    Now if you try re-running the configuration, you might get an UnsupportedClassVersionError if you’ve previously run the tests in console, or at least this happens to me on my Mac. I don’t know the actual root cause, but if this happens, just do Build > Clean Project to clear out previously built classes.

    출처 : 여기

    +0

    개인적으로 시간 가치가 없다고 판단하고 장치에서 실행되는 지원되는 androidTest를 고수했습니다. AS/gradle의 새로운 버전이 이러한 대안을 깰 가능성이 있습니다. 곧 문제가 해결되기를 바랍니다. https://code.google.com/p/android/issues/detail?id=65186 –

    1

    http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments이 robolectric + 안드로이드 스튜디오에 대한 스레드, 어쩌면 약간의 대답은 당신이 도움이 될 것입니다 Android project with Robolectric and Gradle (Android studio)

    업데이트 :

    클래스 경로 수정과 문제 최신 안드로이드 스튜디오 버전 및 그라데이션 아이디어 플러그인을 사용하여 설정 아이디어 출력 경로를 사용하여 피할 수 있습니다

    apply plugin: 'idea'  
    idea { 
        module { 
         outputDir = file('build/resources/testDebug') 
         testOutputDir = file('build/test-classes/debug') 
        } 
    } 
    
    관련 문제