I want to keep a Sting and Raw file in my androidTest module and read it when needed in Espresso test.
I keep res folder under androidTest and able to sync and generate R file for the same. But when I tried to access string resource using
getTargetContext.getString(R.string.product_name)
or using mAcitivityRule.getActivity.getString(R.string.product_name)
I am getting some random value which is even not used anywhere in resource file.
String output: "res/drawable-v21/abc_action_bar_item_background_material.xml"
Is there any way I can keep and use String resource in my project test module and it will not add into my production build.
The basic idea is to use a method with an internal ViewAction that retrieves the text in its perform method. Anonymous classes can only access final fields, so we cannot just let it set a local variable of getText() , but instead an array of String is used to get the string out of the ViewAction .
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string. String Array.
String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc. These views have a common attribute named text.
In 2019 we should do (Kotlin).
val resources = ApplicationProvider.getApplicationContext<App>().resources
val description = resources.getString(DESCRIPTION)
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