mardi 22 mars 2016

Android test : how to access application resource without context activity

I have a resource xml file in res/raw named parameters.xml This file is used through a class called Parameters The class Parameters uses Xpath to extract data from an xml file

In the main activity I've coded this:

Parameters parameters = new Parameters(getResources().openRawResource(R.raw.parameters));

It works fine !

I want to test the Parameters class using the xml resource without Activity ==> I do not have context anymore

at the moment, I've coded a main method inside Parameters class (because I also use this class for other non android projects)

I've tried this: 1- Resources.getSystem().openRawResource(R.raw.parameter) does not work because my xml file is not a system resources 2- create an inner class (inside main method) which extends InstrumentationTestCase does not work : exception runtime stub !

Any idea to fix my problem ? Thanks

Aucun commentaire:

Enregistrer un commentaire