lundi 6 juillet 2015

Android Studio unit tests: How to get resource strings correctly?

I'm trying to get my unit test that includes getting strings resources running, but up to this point I haven't been that successful.

I've already tried several things

  • Getting the strings via the Application context (Application-method "getResourceString" that gets the strings via the Application context; Works when not unit testing and having to get resources without an activity)

  • Creating an ActivityTestCase and getting a context via getInstrumentation().getContext() which gives me a android.content.res.Resources$NotFoundException

  • Creating an activity manually in the TestCase -> not working

So what is the proper way to create a unit test that needs to get strings from the resources of the main project?

Aucun commentaire:

Enregistrer un commentaire