I have made a text file of values that I want to use for testing in res/raw
I want to use them in testing
I am using robolectric
What is the best way of accessing these values?
Thanks
Robolectric provides a JVM compile version of the android. jar file. Robolectric handles views, resource loading, and many other things that are implemented in the Android native. This enables you to run your Android tests in your development environment, without requiring any other setup to run the test.
Robolectric is a framework that brings fast and reliable unit tests to Android. Tests run inside the JVM on your workstation in seconds. With Robolectric you can write tests like this: @RunWith(RobolectricTestRunner.
Robolectric works by creating a runtime environment that includes the real Android framework code. This means when your tests or code under test calls into the Android framework you get a more realistic experience as for the most part the same code is executed as would be on a real device.
You can access your app's resources via your Application instance. Use ApplicationProvider to fetch it from within a unit test:
// replace 'Application' with your actual class if you use a custom one
ApplicationProvider.getApplicationContext<Application>().resources
Ensure includeAndroidResources is set to true in your build.gradle
or your unit tests won't see your resources:
android {
testOptions.unitTests.includeAndroidResources true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With