I’m currently trying to test a third party service for my app, and need to identify each test that is being done at every specific run.
Since more than one test can take place every time I run the testApp, I need to Identify every test.
What I thought of, is storing the device name and build (not many devices here), and an index for each test.
private String getTestId(){
SharedPreferences settings = getPreferences(0);
SharedPreferences.Editor editor = settings.edit();
int testNumber = settings.getInt("id", 0);
editor.putInt("id", testNumber+1);
editor.commit();
String id = Build.DEVICE + Build.VERSION.RELEASE+" - test number: "+testNumber;
return id;
}
Is running this function every time I run a test time consuming, or can I do this without fearing the coast?
if the answer is “time consuming”, what would you suggest I do every time I run a test in order to differentiate every test?
About
SharedPreferences.SharedPreferences caches after first load, so disk access to load data will take time but once. You can try to load SharedPreferences early in your test suite to avoid this penalty.
For persisting your data you should opt for SharedPreferences.Editor.apply() instead of SharedPreferences.Editor.commit() since appy is asynchronous. But please do read the documentation about both to see which one applies in your case.