public
Created

Get asset on test package with ServiceTestCase. (Android)

  • Download Gist
asset_on_servicetest.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import android.content.Context;
import android.content.res.AssetManager;
import android.test.ServiceTestCase;
 
import com.example.android.HogeService;
 
public class HogeTest extends ServiceTestCase<HogeService>
{
private Context getTestContext() throws Exception
{
return (Context)getClass().getMethod("getTestContext").invoke(this);
}
 
public void testHoge() throws Exception
{
AssetManager am = getTestContext().getResources().getAssets();
java.io.InputStream is = am.open("hoge.txt");
try {
// hogehoge
}
finally {
is.close();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.