2014-11-27 4 views
4

robolectric을 사용하여 내 안드로이드 응용 프로그램 테스트에서 일부를 모의하려고합니다. 슬프게도 프로젝트에 외부 라이브러리를 포함시킨 후 테스트가 중단되었습니다. 오류 정보가 일부 라이브러리 리소스를 찾을 수 없습니다.robolectric을 사용하여 지원 라이브러리 리소스를 찾는 방법은 무엇입니까?

java.lang.RuntimeException: Could not find any resource from reference ResName{com.company.app:style/Theme_AppCompat_Light_NoActionBar} from style StyleData{name='AppTheme_Base', parent='Theme_AppCompat_Light_NoActionBar'} with theme null 

누군가가이 문제를 가지고 있습니까?

+1

충돌에 대한 세부 정보를 포함 할 수 있습니까? "오류 정보는 일부 라이브러리 리소스가 없습니다"라는 메시지가 있습니다 ... 여기에도 게시 할 수 있습니까? –

+0

@MikeLaren 감사합니다. Guilherme Torres 카스트로가 문제를 발견했습니다! –

답변

8

내부 리소스 (AKA aar)가 포함 된 라이브러리는 project.properties 파일 (src/main)에 매핑되어야합니다. (당신이 안드로이드 Studio를 사용하는 경우) 파일의 내용은 다음과 같이 될 것입니다 :

android.library.reference.1=../app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0 

documentation를 살펴 보자.

+0

이것은 Robolectric와 함께 AppCompat 테마와 ActionBarActivity를 사용할 때와 같은 문제를 수정했습니다. 감사합니다! –

-1

Robolectric에서 res 디렉토리를 찾는 데 문제가있을 때 발생합니다. 사용자 정의 테스트 러너를 작성하여 올바른 경로를 res 디렉토리에 지정할 수 있습니다.

public class CustomTestRunner extends RobolectricTestRunner { 

public CustomTestRunner(Class<?> testClass) throws InitializationError { 
    super(testClass); 
} 

@Override 
protected AndroidManifest getAppManifest(Config config) { 
    final String BUILD_PATH = "src/main"; 
    final FileFsFile manifestFile = FileFsFile.from(BUILD_PATH, "AndroidManifest.xml"); 

    AndroidManifest appManifest = super.getAppManifest(config); 
    return new AndroidManifest(manifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory()); 
} 
} 

는 교체 사용 :

@RunWith(RobolectricTestRunner.class)로 : 당신의 Robolectric 테스트에서 RunWith(MyRobolectricTestRunner.class).

내 경우에 appManifest.getResDirectory()"build/intermediates/res/merged/debug"을 반환했습니다.

관련 문제