Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old May 5th, 2009, 09:29 PM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: May 2009
Posts: 18
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Contexts in a JUnit test?

I've got a class that interfaces with the preferences that I'd like to unit test, but I can't figure out a way to pass it a context it can use for getSharedPreferences. Is there an easy (or even not-so-easy) way to do so?

Thanks!

James McMurray is offline  
Reply With Quote
sponsored links
Old May 18th, 2009, 11:02 PM   #2 (permalink)
New Member
 
Join Date: May 2009
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just in case you haven't already found this out for yourself in the past two weeks, I suggest you have a look at My life with Android :-): JUnit in Android for an excellent article on JUnit and Android complete with a good example. To answer your question specifically, if your test cases inherit from android.test.AndroidTestCase instead of junit.framework.TestCase, you can call getContext() to get an Android Context.
HTH
Brian.
bwin is offline  
Reply With Quote
Old May 19th, 2009, 10:06 AM   #3 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: May 2009
Posts: 18
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! I've been using the Activity Test Case with a dummy activity, but this way is much cleaner.
James McMurray is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:18 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.