how8586 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Error while getting Context #447

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Create a test project with junit4
2. Write test cases
3. Try to get Context

We should be able to get the Context.

Using JDK 1.6, Android library, junit4.4 library, and all Powermock libraries

I have written test cases for my application. but for some cases, I need to 
have the Context. but I am unable to get it.

Can you please help me to how to get application context using junit framework?

Help appreciated.

Thanks
Subeer

Original issue reported on code.google.com by subeer.v...@gmail.com on 13 Jun 2013 at 6:04

GoogleCodeExporter commented 9 years ago
What do you mean getting the context? Which context? PowerMock doesn't have a 
"context"?!

Original comment by johan.ha...@gmail.com on 16 Jun 2013 at 5:34

GoogleCodeExporter commented 9 years ago
Hi John,
Actually I was talking about application context. Sorry i missed to mention 
this. But I got the solution for this.

But , now I have a problem with accessing my application resource(like 
res/string) from test application.
Actually, when i try to access my application string using Roboelectric from my 
Test application(A Java app), it could not reach up to my application's 
res/values/strings.xml. When I try to get the string id from context, it always 
gives me string's id as '0'.

Can you please help me on this?

Thanks
Subeer

Original comment by subeer.v...@gmail.com on 17 Jun 2013 at 7:56

GoogleCodeExporter commented 9 years ago
Is this a PowerMock question or Roboletric question!? I can't help you with 
roboletric stuff :/

Original comment by johan.ha...@gmail.com on 17 Jun 2013 at 8:29

GoogleCodeExporter commented 9 years ago
Oh is that so! No problem. 
Can you please let me know if we would have been using Powermock, then how can 
we get the string id from activity's context.

I am getting context from my test application(Java application) like this:

MyActivity myactivity = new MyActivity();

Now , I am using this context(myactivity) to get the stringId of my actual 
application from my test application. But it always gives me stringId as 0.

Please help.
Thanks

Original comment by subeer.v...@gmail.com on 17 Jun 2013 at 10:00

GoogleCodeExporter commented 9 years ago
Sorry but I'm not too familiar with Android.

Original comment by johan.ha...@gmail.com on 18 Jun 2013 at 5:41