Resource management in Robolectric

Resource management in Robolectric

Bbe9718bebdafbdc8dabbe3cadf1bc46?s=128

Keishin Yokomaku

January 13, 2017
Tweet

Transcript

  1. Resource management in Robolectric Keishin Yokomaku / potatotips #36 @

    Money Forward, Inc.
  2. 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
  3. 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
  4. Resource management in Robolectric 4 ·ͩ3PCPMFDUSJDͰ ফ໣ͯ͠Δͷʁ

  5. Resource management in Robolectric 5 ؾܰʹݴͬͯ͘ΕΔͳ͋

  6. 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
  7. 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
  8. Resource management in Robolectric 8

  9. Resource management in Robolectric 9

  10. Resource management in Robolectric 10

  11. Resource management in Robolectric 11

  12. 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
  13. 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
  14. 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: ͍͍͑
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. Resource management in Robolectric Keishin Yokomaku / potatotips #36 @

    Money Forward, Inc.
  36. DroidKaigi Tickets available! http://bit.ly/2gFFK8z 36