2011-07-26 40 views
3

我已经提出,我想用在水库测试值的文本文件/原始
我想使用它们在测试中
我使用我如何在我的测试类访问资源robolectric
访问这些值的最佳方式是什么?
感谢使用robolectric时

回答

0

我这样做是:

int resourceId = Robolectric.getShadowApplication().getResources() 
       .getIdentifier("myaudio","raw", Robolectric.getShadowApplication().getPackageName()); 

if (resourceId != 0) { // Raw folder contains resource. 
    assertTrue(true); 
} else {    // Raw folder doesn't contain resource. 
    assertTrue(false); 
} 

希望这有助于... ! 谢谢.. !!

+1

为什么不使用'RuntimeEnvironment.application'而不是** Robolectric.getShadowApplication **? –

相关问题