Get meta-data from manifest in UnitTest

Paul

I'm currently running into trouble retrieving <meta-data> tags from my AndroidManifest file while being inside an InstrumentationTest.

I am using a library (Sugar ORM) which stores some essential information inside these tags. As soon as I use the library inside the code to be tested I run into problems.

AndroidManifest.xml

<manifest package="org.something" ...>
    ...
    <application ...>
        <meta-data android:name="DATABASE" android:value="foo.db" />
        ...
    </application>
</manifest>

Retrieval of the metadata works like that:

PackageManager pm = context.getPackageManager();
try {
    ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
    value = ai.metaData.getString(name);
} catch (Exception e) {
    Log.d("sugar", "Couldn't find config value: " + name);
}

The test is running as a InstrumentationTestCase and sets up the context to be getInstrumentation().getContext().

Snikk

The problem is that InstrumentationTestCase does not contain the meta data from your application. All you need to do is extend ApplicationTestCase<Application> for your test case class.

You can call getContext() in your test cases and that will have the appropriate information in there.

PackageManager pm = getContext().getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to read meta data from Manifest file

From Java

Get all WooCommerce products from a category that have specific meta data

From Dev

How to get meta data from WooCommerce product attribute terms

From Dev

Trying to get image URL from meta data of custom post

From Dev

Trying to get user id and user meta data from WordPress database

From Dev

unittest data from setUpClass to setUp

From Dev

unittest data from setUpClass to setUp

From Dev

How to write meta-data info to Android Manifest at runtime

From Dev

android+gradle: different manifest meta-data per flavor

From Dev

Android Manifest doesn't find <meta-data>

From Dev

How to read manifest.mf from *.war/META-INF/MANIFEST.MF file?

From Dev

Get header status code from stream_get_meta_data array

From Dev

how to get from a .exe (executable file) the version, author, publisher etc and other meta data without running the .exe

From Dev

How to get meta data with MMPython for images and video

From Dev

How to get PDF meta data using MUPDF

From Dev

how to get Tree meta data in fancytree jquery

From Dev

Where to put the API key? Resources, Meta-data in Manifest or static variable?

From Dev

ember js get meta informations from json

From Dev

Get Meta_Value from WP database

From Dev

Wordpress - get the userID from custom user meta

From Dev

Get meta description from external website

From Dev

Get meta description from external website

From Dev

Get Meta_Value from WP database

From Dev

Parsing annotation meta data from an ejb proxy

From Dev

how to exclude meta data from elasticsearch results?

From Dev

Adding Meta data to a codeigniter view from a controller

From Dev

Parsing annotation meta data from an ejb proxy

From Dev

Meta data from Parse.com

From Dev

Dropbox file meta data from shared link

Related Related

  1. 1

    How to read meta data from Manifest file

  2. 2

    Get all WooCommerce products from a category that have specific meta data

  3. 3

    How to get meta data from WooCommerce product attribute terms

  4. 4

    Trying to get image URL from meta data of custom post

  5. 5

    Trying to get user id and user meta data from WordPress database

  6. 6

    unittest data from setUpClass to setUp

  7. 7

    unittest data from setUpClass to setUp

  8. 8

    How to write meta-data info to Android Manifest at runtime

  9. 9

    android+gradle: different manifest meta-data per flavor

  10. 10

    Android Manifest doesn't find <meta-data>

  11. 11

    How to read manifest.mf from *.war/META-INF/MANIFEST.MF file?

  12. 12

    Get header status code from stream_get_meta_data array

  13. 13

    how to get from a .exe (executable file) the version, author, publisher etc and other meta data without running the .exe

  14. 14

    How to get meta data with MMPython for images and video

  15. 15

    How to get PDF meta data using MUPDF

  16. 16

    how to get Tree meta data in fancytree jquery

  17. 17

    Where to put the API key? Resources, Meta-data in Manifest or static variable?

  18. 18

    ember js get meta informations from json

  19. 19

    Get Meta_Value from WP database

  20. 20

    Wordpress - get the userID from custom user meta

  21. 21

    Get meta description from external website

  22. 22

    Get meta description from external website

  23. 23

    Get Meta_Value from WP database

  24. 24

    Parsing annotation meta data from an ejb proxy

  25. 25

    how to exclude meta data from elasticsearch results?

  26. 26

    Adding Meta data to a codeigniter view from a controller

  27. 27

    Parsing annotation meta data from an ejb proxy

  28. 28

    Meta data from Parse.com

  29. 29

    Dropbox file meta data from shared link

HotTag

Archive