Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Resource management in Robolectric

Resource management in Robolectric

Keishin Yokomaku

January 13, 2017
Tweet

More Decks by Keishin Yokomaku

Other Decks in Technology

Transcript

  1. Resource management in Robolectric About Me ▸ Keishin Yokomaku ▸

    Drivemode, Inc. / Principal Engineer ▸ KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow ▸ Books: Android Academia / Grimoire of Android / Nanairo Android ▸ Fun: Gymnastics / Cycling / Photography / Motorsport ▸ Today’s Quote: “Happy DroidKaigi!” 2
  2. Resource management in Robolectric Robolectric? ▸ Android testing framework running

    on JVM ▸ Emulates Android framework behavior in JVM, instead of device or emulator ▸ Has tons of mock implementation on framework and system services ▸ Popular choice of testing framework in Android development ▸ Frequently combined with Mockito 3
  3. Resource management in Robolectric Latest update in Robolectric ▸ API

    24 & 25 support ▸ Configuration file location change ▸ $app_module/src/test/resources/your/package/name/robolectric.properties ▸ Resource loading updates & modifications ▸ Easy customization for RobolectricTestRunner ▸ etc… 6
  4. Resource management in Robolectric Latest update in Robolectric ▸ API

    24 & 25 support ▸ Configuration file location change ▸ $app_module/src/test/resources/your/package/name/robolectric.properties ▸ Resource loading updates & modifications ▸ Easy customization for RobolectricTestRunner ▸ etc… 7
  5. Resource management in Robolectric Steps to execute a test method

    1.Load test class 2.Invoke @BeforeClass if any 3.Set up test environment based on @Config or robolectric.properties 4.Reset static states 5.Load system resources and app resources 6.Invoke @Before, @Test, @After methods 12
  6. Resource management in Robolectric Steps to execute a test method

    1.Load test class 2.Invoke @BeforeClass if any 3.Set up test environment based on @Config or robolectric.properties 4.Reset static states 5.Load system resources and app resources 6.Invoke @Before, @Test, @After methods 13
  7. Resource management in Robolectric From Robolectric 3.1.3 ▸ Robolectric has

    a table which maps all resources (app and system resources) ▸ Put all resources in the memory 14 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑
  8. Resource management in Robolectric How to resolve resource from resource

    id in the test 15 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ context.getString(R.string.no) # R.string.no => 17049821
  9. Resource management in Robolectric How to resolve resource from resource

    id in the test 16 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 context.getString(R.string.no) # R.string.no => 17049821
  10. Resource management in Robolectric How to resolve resource from resource

    id in the test 17 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 context.getString(R.string.no) # R.string.no => 17049821
  11. Resource management in Robolectric How to resolve resource from resource

    id in the test 18 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 context.getString(R.string.no) # R.string.no => 17049821
  12. Resource management in Robolectric How to resolve resource from resource

    id in the test 19 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources context.getString(R.string.no) # R.string.no => 17049821
  13. Resource management in Robolectric How to resolve resource from resource

    id in the test 20 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources context.getString(R.string.no) # R.string.no => 17049821
  14. Resource management in Robolectric How to resolve resource from resource

    id in the test 21 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) context.getString(R.string.no) # R.string.no => 17049821
  15. Resource management in Robolectric How to resolve resource from resource

    id in the test 22 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} context.getString(R.string.no) # R.string.no => 17049821
  16. Resource management in Robolectric How to resolve resource from resource

    id in the test 23 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string context.getString(R.string.no) # R.string.no => 17049821
  17. Resource management in Robolectric How to resolve resource from resource

    id in the test 24 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string context.getString(R.string.no) # R.string.no => 17049821
  18. Resource management in Robolectric How to resolve resource from resource

    id in the test 25 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} context.getString(R.string.no) # R.string.no => 17049821
  19. Resource management in Robolectric How to resolve resource from resource

    id in the test 26 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/ok} context.getString(R.string.no) # R.string.no => 17049821
  20. Resource management in Robolectric How to resolve resource from resource

    id in the test 27 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/yes} context.getString(R.string.no) # R.string.no => 17049821
  21. Resource management in Robolectric How to resolve resource from resource

    id in the test 28 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} context.getString(R.string.no) # R.string.no => 17049821
  22. Resource management in Robolectric How to resolve resource from resource

    id in the test 29 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} context.getString(R.string.no) # R.string.no => 17049821
  23. Resource management in Robolectric How to resolve resource from resource

    id in the test 30 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} context.getString(R.string.no) # R.string.no => 17049821
  24. Resource management in Robolectric How to resolve resource from resource

    id in the test 31 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} RuntimeEnvironment.getQualifiers() context.getString(R.string.no) # R.string.no => 17049821
  25. Resource management in Robolectric How to resolve resource from resource

    id in the test 32 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} RuntimeEnvironment.getQualifiers() en context.getString(R.string.no) # R.string.no => 17049821
  26. Resource management in Robolectric How to resolve resource from resource

    id in the test 33 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} RuntimeEnvironment.getQualifiers() en context.getString(R.string.no) # R.string.no => 17049821
  27. Resource management in Robolectric How to resolve resource from resource

    id in the test 34 System Resources App Resources AssetManager string drawable layout ok yes no en: No fr: Non ja: ͍͍͑ 1000001000000000001001100 >>> 24 0000000000000000000000001 == pointing to System Resources ResourceIndex#getResName(resourceId) ResName{android:string/no} type == string ResName{android:string/no} ResName{android:string/no} RuntimeEnvironment.getQualifiers() en context.getString(R.string.no) => “No” # R.string.no => 17049821