OK, I found a solution: I created a context to our test package and was able to access the assets:
mTestAppContext = getContext().createPackageContext("com.blah.test", Context.CONTEXT_IGNORE_SECURITY); Just in case anyone else needs a workaround. On Feb 4, 10:36 am, nate <nat...@cisco.com> wrote: > Also, i put the test assets in the target project's directory and was > able to access them with: > > getSystemContext().getAssets().list(".") > > On Feb 4, 10:31 am, nate <nroy...@gmail.com> wrote: > > > > > > > > > I checked my setUp() method and I do call super.setUp() as the first > > line. The reason I believe the contexts are the same are two-fold: > > > I tried both: > > > getSystemContext().getAssets().list(".") > > getContext().getAssets().open("."); > > > and neither of them listed any files. The second reason is that I > > read the code for ServiceTestCase and saw that the getSystemContext() > > is just the > > same context retrieved by getContext(), but it's grabbed before any > > tests have a chance to mess with it(according to the comment in the > > code): > > > @Override > > protected void setUp() throws Exception { > > super.setUp(); > > > // get the real context, before the individual tests have a > > chance to muck with it > > mSystemContext = getContext(); > > > } > > > So it would seem that getting the context to the app the testcase is > > in is not possible with the ServiceTestCase, unless I am missing > > something. > > > On Feb 3, 9:15 pm, "A. Elk" <lancaster.dambust...@gmail.com> wrote: > > > > What leads you to believe that both Context objects contain the same > > > information? If you do a getSystemContext() you should get the context > > > that's stored during setUp(). The only thing that might screw this up > > > is if you overrode setUp() but forgot to call super.setUp() first. > > > > On Feb 2, 2:08 pm, nate <nroy...@gmail.com> wrote: > > > > > Hey Everyone, > > > > I don't know if I am doing something wrong here, but when I am > > > > trying to use the ServiceTestCase class to test my Service, I cannot > > > > get a context which points to the test project. getContext() and > > > > getSystemContext() both seem to point to the target project's > > > > context. The reason I need the context of my test app is that i have > > > > some assets which i need to be able to use in order to test the > > > > service in question. Does anyone know of a workaround or could point > > > > me at a way of resolving this? (i looked through the source of > > > > ServiceTestCase and didn't see another way) > > > > > Something similar to instrumentationtestcase's > > > > getInstrumentation.getContext() is what I am looking for. > > > > > Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en